我的 iOS 应用程序似乎遇到了困难。
它的部署目标是 iOS5.0,但是我使用的是 iOS 6.0 SDK。
在我的视图控制器中,我有:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
这在 iOS5 模拟器中运行时效果很好。视图不会旋转到 LandScape 或倒置。
但是,在 IOS6 模拟器中(以及在设备上),它将继续旋转。
我曾经NSLog
检查过-supportedInterfaceOrientations
确实被调用了,并且确实调用了两次,但是它仍然旋转到 LandScape (右或左)
我究竟做错了什么?
我还扩展了UINavigationController
(我的根视图控制器)以包含以下内容:
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
但仍然没有成功。
编辑
根据马特的回答。我还需要使用与我的 UINavigationController 类似的实现来扩展 UITabBarController 并且这很有效。