[英]iOS7 - AutoRotate is not getting invoked
球队,
我正在做一个支持项目,并且我对iPhone有基本的了解。 当我在设备中更改方向时,以下方法都不会在更改方向时被调用。
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
// your code for portrait mode
}
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait;
//return here which orientation you are going to support
}
我通过presentViewController推送屏幕,并且在推送屏幕之前调用了上面的方法,但是在推送屏幕后以及更改方向时什么都没有。
另外,我尝试按照以下说明创建类别,但我收到viewController not found错误,不确定我在这里缺少什么...
在IOS7中,如果使用UINavigationController,则旋转处理方式不同!
看到UINavigationController,可以看到它是UIViewController的子类,那么那就是在他上面列出了轮换的处理方法; 因此,我们还需要使用UINavigationController进行旋转处理,
我的方法是将类别添加到UINavigationController,这样做。
在类别中。 M写
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
任何帮助是极大的赞赏!
对我来说,其他两个功能也可以使用,但是您可以尝试使用下面的委托
从Apple Docs:
在用户界面开始旋转之前发送给视图控制器。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
持续时间:(NSTimeInterval)duration
用户界面旋转后发送到视图控制器:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.