iOS:如何在 iOS 8.3 中禁用自动旋转?我在网上找到的解决方案都没有用

标签 ios cocoa-touch interface-orientation

我正在尝试在 iOS 上强制显示我的应用程序的纵向 View 。这应该是一件简单的事情,但我在网上找到的解决方案似乎都不起作用。这是我的 View Controller 中的代码段:

- ( void )viewWillAppear:( BOOL )animated
{
    [ super viewWillAppear:animated ];

    [ [ UIDevice currentDevice ] setValue:@( 1 ) forKey:@"orientation" ];
}

-(BOOL) shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation {
    return NO;
}

- (BOOL)shouldAutorotate {
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations {
//  return UIInterfaceOrientationMaskPortrait;   //tried both
    return UIInterfaceOrientationPortrait;
}

这是我在网上找到的几个解决方案/帖子的结合,我的应用程序仍然“像魅力一样旋转”。有什么明显的我想念的吗?我正在为 iOS 8.3 开发 Xcode 6.3。

谢谢!

最佳答案

如果您想在整个应用程序中强制使用纵向,只需在项目“常规”目标设置的“部署信息”部分设置支持的界面方向,此处:enter image description here

关于iOS:如何在 iOS 8.3 中禁用自动旋转?我在网上找到的解决方案都没有用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29757481/

相关文章:

ios - 测试时默认 undoManager 为 nil

ios - AutoLayout - 如何绑定(bind)两个 View 并相应地更改大小

ios - 自 XCode 版本 6.1 (6A1052d) 更新以来,我收到 'NSCalendar?' does not have a member named 'components' 错误

objective-c - 如何更改 modalTransitionStyle?

ios - 在方向被另一个(iOS)强制横向后,如何恢复 UIViewController 的正确方向?

ios - 现代 Xcode 5 iOS7 项目中创建的 UIWindow 在哪里?

ios - PNG 预乘 Alpha,iOS 模拟器与 iPad

iphone - 核心数据中的 mach_msg_trap

ios - 界面方向和设备方向的区别?

iphone - 无法将界面方向旋转为纵向颠倒