在iOS 7中强制横向和自动旋转
我的应用程序应该只是风景,我没有任何问题,当为iOS 6和更早版本build设。 现在使用iOS 7,它将不会旋转。
在我的应用程序设置中,我已将其设置为仅左右alignment。 在我的视图控制器中,我使用以下内容:
- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight; }
我也习惯使用这个,现在已经弃用了:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { return UIInterfaceOrientationIsLandscape(orientation); }
新的似乎是shouldAutorotate,但使用这崩溃我的应用程序。 任何想法,将不胜感激,因为我的应用程序被迫在我的iPad和模拟器上的肖像。 谢谢!
这解决了我的问题。 我不知道为什么我之前有问题,但我一定错过了尝试这个确切的组合(也,info.plist应该有支持的方向设置)。
(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } (BOOL)shouldAutorotate { return YES; }
编辑:我可能有模拟器的问题,做一个重置/重新启动和干净可能有助于修复。
在你的代码中包含这个方法:
- (BOOL)shouldAutorotate{ if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft ||[[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight) { return YES; } else{ return NO; } }
阅读更多信息。 这里提到我们应该重写shouldAutorotate
来压制方向。
如果要暂时禁用自动旋转function,请避免操作方向遮罩来执行此操作。 相反,重写最顶层视图控制器上的shouldAutorotate方法。 在执行任何自转之前调用此方法。 如果它返回NO,那么旋转被抑制。
我不知道为什么,但是这个工作在IOS 7上
[[UIApplication sharedApplication] setStatusBarHidden:NO]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; [super willRotateToInterfaceOrientation:UIInterfaceOrientationPortrait duration:0];
我可能有模拟器的问题,做一个重置/重新启动和清理可能有助于修复。
这对我工作:(模拟器 – >重置内容和设置…)