iphone-在更改iphone的方向时,只旋转一个控件,而不旋转所有其他控件
我有UIImageView,视图中有一些标签、按钮等。 目前我已经实现了肖像模式。 当iphone的方向改变时,我只想旋转图像视图。Rest所有其他控件都不应更改。iphone-在更改iphone的方向时,只旋转一个控件,而不旋转所有其他控件,iphone,uiimageview,orientation,Iphone,Uiimageview,Orientation,我有UIImageView,视图中有一些标签、按钮等。 目前我已经实现了肖像模式。 当iphone的方向改变时,我只想旋转图像视图。Rest所有其他控件都不应更改。 如何实现仅图像视图的旋转?最近我不得不做一些非常类似的事情。我所做的是禁用自动旋转,然后使用如下设备通知: [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] a
如何实现仅图像视图的旋转?最近我不得不做一些非常类似的事情。我所做的是禁用自动旋转,然后使用如下设备通知:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
- (void)didRotate:(NSNotification *)notification {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
switch (orientation) {
case UIDeviceOrientationUnknown:
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
return;
break;
}
// Do something
}
您需要处理一些情况,如快速旋转等。如果您需要更多信息,请告诉我。谢谢您的回复。但几乎不需要澄清。我是否必须创建从ImageView继承的不同视图类并处理它,或者我可以在viewController本身中处理“didRotate”?我的建议是在视图控制器中处理这个问题。也许可以在viewDidLoad中设置观察者。任何方向更改都将立即发送通知。因此,我保存了方向更改,并将动画按原样设置。如果在动画期间有另一个方向更改,我将重新开始动画,直到没有更改为止。