Ios6 检测UIViewController上的接口旋转,即使未在-(NSUInteger)supportedInterfaceOrientations中定义
我有一个UIViewController在主视图上处理几个UIImageView。底部是一个UIToolbar,其中有几个项目可供交互 现在,当我旋转设备时,我不希望viewController旋转,只希望UIImageView旋转。换句话说,底部的工具栏将位于左侧(或右侧),但图像视图将正确旋转 那么通过使用这些方法,Ios6 检测UIViewController上的接口旋转,即使未在-(NSUInteger)supportedInterfaceOrientations中定义,ios6,Ios6,我有一个UIViewController在主视图上处理几个UIImageView。底部是一个UIToolbar,其中有几个项目可供交互 现在,当我旋转设备时,我不希望viewController旋转,只希望UIImageView旋转。换句话说,底部的工具栏将位于左侧(或右侧),但图像视图将正确旋转 那么通过使用这些方法, - (BOOL)shouldAutoRotate { return YES; } 结合 - (NSUInteger)supportedInterfaceOrientat
- (BOOL)shouldAutoRotate {
return YES;
}
结合
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
及
不会执行设备上的任何旋转,因为只支持一个接口方向(UIInterfaceOrientationMaskPortrait
)。但是,当我在supportedInterfaceOrientions
-方法中添加另一个要支持的界面方向时,视图控制器也会旋转
即使只支持一个方向,如何检测视图控制器的旋转?或者,是否存在另一种根据设备方向的变化旋转UIView的可能性
谢谢你的帮助 尝试使用UIDevice实例检测设备物理方向的变化。 要开始接收通知,您可以使用如下方式(例如,在
视图中将出现:
方法):
对于取消注册接收设备旋转事件,请使用此选项(例如,在视图中将消失:
):
这是deviceidrotate
函数的一个示例:
- (void)deviceDidRotate {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
switch (orientation) {
case UIDeviceOrientationPortrait:
case UIDeviceOrientationPortraitUpsideDown:
// do something for portrait orientation
break;
case UIDeviceOrientationLandscapeLeft:
case UIDeviceOrientationLandscapeRight:
// do something for landscape orientation
break;
default:
break;
}
}
找到答案-当然-10秒后在这里:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//No reason to ask NSNotification because it many cases `userInfo` equals to
//@{UIDeviceOrientationRotateAnimatedUserInfoKey = 1;}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceDidRotate) name:@UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)deviceDidRotate {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
switch (orientation) {
case UIDeviceOrientationPortrait:
case UIDeviceOrientationPortraitUpsideDown:
// do something for portrait orientation
break;
case UIDeviceOrientationLandscapeLeft:
case UIDeviceOrientationLandscapeRight:
// do something for landscape orientation
break;
default:
break;
}
}