支持接口方向设置在模拟器中正常工作



我有一个项目,其中所有视图都只能纵向显示,除了一个只有横向而没有自动旋转的视图。我在项目设置中将支持的方向设置为纵向和横向。然后,我为每个视图控制器设置这些函数:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft; // or Right of course
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotate
{
    return NO;
}

但它不起作用。模拟器允许所有视图旋转,并且似乎完全忽略了设置。我做错了什么,还是模拟器中的错误?

最有可能的问题在于您已在 info.plist 中定义了允许的方向,该方向会覆盖代码中指定的任何内容。

因此,您可能需要从 info.plist 中删除条目。

我最终不得不使用一些技巧来让它工作:我把这一行放在视图中DidLoad:self.view.transform = CGAffineTransformMakeRotation(M_PI/2);现在一切正常

最新更新