Iphone iOS7-未调用自动旋转
团队 我正在做一个支持项目,我对iPhone有基本的了解。当我在设备中更改方向时,在更改方向时不会调用以下任何方法Iphone iOS7-未调用自动旋转,iphone,ios7,Iphone,Ios7,团队 我正在做一个支持项目,我对iPhone有基本的了解。当我在设备中更改方向时,在更改方向时不会调用以下任何方法 - (BOOL)shouldAutorotate { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait) {
- (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未找到错误,不确定我在这里缺少什么
如果使用UINavigationController,则旋转处理方式不同
看到UINavigationController,可以看到它是UIViewController的一个子类,那么就是在他上面列出了有旋转的处理方法;所以我们需要使用UINavigationController进行旋转处理
我的方法是向UINavigationController添加一个类别,这样做
在类别中。M写
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
非常感谢您的帮助 对我来说,其他两个函数也在工作,但您可以尝试使用下面的委托 来自苹果文档: 在用户界面开始之前发送到视图控制器 旋转
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
持续时间:NSTimeIntervalduration
在用户界面旋转后发送到视图控制器:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation