队员们,
我正在做一个支持项目,我对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找不到错误,不确定我这里错过了什么…
在IOS7中,如果你使用UINavigationController,旋转处理的方式是不同的!
见UINavigationController,可以看出它是UIViewController的一个子类,那就是在他上面有列出的旋转处理方法;所以我们需要用UINavigationController也做旋转处理,
我的方法是向UINavigationController添加一个类别,这样做。
在类别中。M次写入
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}任何帮助都是非常感谢的!
发布于 2014-02-28 01:55:06
对我来说,其他两个函数也是有效的,但您可以尝试使用下面的委托
来自Apple Docs:
在用户界面开始rotating.
持续时间:(NSTimeInterval)持续时间
在用户界面旋转后发送到视图控制器:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
https://stackoverflow.com/questions/22076305
复制相似问题