objective-c - shouldAutorotate 返回 true 但不旋转

标签 objective-c ios xcode ipad ios6

我的第一个 View Controller 是 LoginViewController。我正在尝试支持 iOS 6 上的自动旋转管理。

我已经实现了 shouldAutorotate 而不是 shouldAutorotateToInterfaceOrientation,如下所示:

-(BOOL)shouldAutorotate {
   UIInterfaceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];

   return [DeviceSupport isOrientationSupported:toInterfaceOrientation];
}

shouldAutorotate 在应用程序启动时被调用五次。 toInterfaceOrientation 值按顺序排列且不改变 ipad 方向:0、0、0、4 和 4。首先,为什么应用需要这么长时间才能将正确的方向放入 currentDevice?为什么 shouldAutorotate 被调用了五次?

当方向为 4 时,[DeviceSupport isOrientationSupported:toInterfaceOrientation] 返回 true。但是我的应用程序不旋转。

在我的 info.plist 中:

Supported interface orientations
=> Item 0: Portrait (bottom home button)
=> Item 1: Portrait (top home button)

Supported interface orientations (iPad)
=> Item 0: Landscape (left home button)
=> Item 1: Landscape (right home button)

有什么想法吗?谢谢。

最佳答案

更改您的代码:

[self.window addSubview:aController.view];

此代码:

self.window.rootViewController = aController;

同时添加以下方向支持方法

shouldAutorotate -return YES

supportedInterfaceOrientations- 返回 UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;

关于objective-c - shouldAutorotate 返回 true 但不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13290572/

相关文章:

ios - 全局变量不能正常工作

iphone - 核心数据出现严重的应用程序错误

ios - 访问窗口属性应用程序委托(delegate) iOS

ios - CoreBluetooth 状态保存问题 : willRestoreState not called in iOS 7. 1

iOS 9 即使应用程序终止也如何获取位置

ios - 什么是 start_wqthread?它会影响 UIMainThread 吗?

iphone - iPad制作电子相册的这种控件哪里找

ios - event.touchesForView().AnyObject() 在 Xcode 6.3 中不起作用

iphone - 简单表格导航帮助

ios - 应用程序在设备上启动前卡住几秒钟