ios - 在 iOS 7 中设置方向

标签 ios uiviewcontroller uinavigationcontroller orientation ios7

我的 uiviewcontroller.m 文件中有以下代码:

-(BOOL)shouldAutoRotate
{
    return YES or NO;
}

我已经尝试了 YES 和 NO 但我的 View Controller 仍然旋转?我使用的是 iOS 7,我发现其他 iOS 解决方案也不适合我。

最佳答案

这可能是因为您的 Controller 在 View 层次结构中实例化为 UINavigationController 的子级。 UINavigationController 不会查询子 Controller 是否要旋转。

我遇到了同样的问题;我想禁用自动旋转,所以特定 UINavigationController 的所有层次结构都被锁定在 Portrait 中。我结束了这个类:

@implementation FixedOrientationNavigationController

- (BOOL)shouldAutorotate {
    return NO;
}

@end

我将它代替 UINavigationControllr 类放在 Storyboard 中,用于层次结构,我需要锁定 Portrait。只是这样,我不需要在每个 Controller 中实现 shouldAutorotate

您也可以查看此链接:Orientation Respectful UINavigationController ,它试图实现“尊重方向”的 UINavigationController。 它可以工作,但在某些情况下会导致奇怪的结果,例如,当用户旋转到横向然后返回到应该只支持纵向的 Controller 时。

关于ios - 在 iOS 7 中设置方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18997960/

相关文章:

iphone - 如何将字符串值从一个.m文件传递到另一个.m文件

objective-c - 在 UIViewController 的 viewDidUnload 中释放 IBOutlets?

iphone - 导航项未出现在 View Controller 上

iphone - 从模态视图 Controller 推送 UIViewController

ios - 根据时间更改 uiNavigationController

ios - 我有一个 2 按钮 UIAlertView,我怎么知道按下了哪个按钮?

iphone - 视网膜在我的开发者 iphone 中工作吗?

IOS如何设置日期格式

ios - 如何更改详细 View Controller 中的后退按钮颜色?

ios - 一台mac创建2个证书