[英]iOS 6 autorotation in simulator varies from actual iOS 6 device
My app will not autorotate in the iOS 6 GM simulator but it does with the same version of iOS on the device. 我的应用程序不会在iOS 6 GM模拟器中自动旋转,但它在设备上使用相同版本的iOS。 Could this be a simulator bug? 这可能是一个模拟器错误吗? The app is using deprecated autorotation methods, but they are working fine on the device itself which makes me wonder if the simulator APIs are different? 该应用程序正在使用已弃用的自动旋转方法,但它们在设备本身上工作正常,这让我想知道模拟器API是否不同?
It should still work with the deprecated rotate methods, but you need to add the following to your didFinishLaunchingWithOptions:
method: 它应该仍然适用于已弃用的旋转方法,但您需要将以下内容添加到didFinishLaunchingWithOptions:
方法:
self.window.rootViewController = yourRootViewController;
This tells the main window
what view controller to send the rotate notifications to. 这告诉主window
将旋转通知发送到哪个视图控制器。 This is new with the iOS 6.0 SDK. 这是iOS 6.0 SDK的新功能。
This is what I added to get my app working again: 这是我为了让我的应用再次运行而添加的内容:
// Tell the system what we support
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Adding the following was not enough to make it work on the simulator: 添加以下内容还不足以使其在模拟器上运行:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL) shouldAutorotate {
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
To make it work, I also added the following inside the didFinishLaunchingWithOptions function of the appDelegate class: 为了使它工作,我还在appDelegate类的didFinishLaunchingWithOptions函数中添加了以下内容:
self.window.rootViewController = viewController;
I stopped getting the following error after this addition: Application windows are expected to have a root view controller at the end of application launch 这次添加后我停止了以下错误: 应用程序窗口应该在应用程序启动结束时有一个根视图控制器
- (BOOL)shouldAutorotate {
return NO;
}
and set the supported rotations for the root view controller in the app plist file to only portrait. 并将app plist文件中根视图控制器支持的旋转设置为仅纵向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.