简体   繁体   English

模拟器中的iOS 6自动旋转与实际的iOS 6设备不同

[英]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.

相关问题 自动旋转仅在设备上的模拟器中有效(IOS 7.1) - Autorotation only working in simulator not on device (IOS 7.1) iOS 11设备方向自动旋转 - iOS 11 Device Orientation Autorotation 在模拟器和实际iOS设备上存储文件 - Storing files on simulator vs actual iOS device 在实际设备上发生SIGSEGV错误,但在iOS模拟器上未发生 - SIGSEGV Error occurs on the actual device but not on ios simulator 适用于iOS的Dropbox SDK适用于模拟器,而不适用于实际设备 - Dropbox SDK for iOS works on simulator, not on actual device 模拟器中的iOS应用布局与实际设备上的布局不同 - iOS app layout in the simulator different than on the actual device 音频文件可在iOS模拟器中运行,但无法在实际设备上找到 - Audio files working in iOS simulator, but can't be found on actual device ios 模拟器和实际设备中的捆绑行为不同 - Bundle behaviour differs inside ios simulator and actual device ios9-Xcode 7-Swift-键盘在模拟器中正确显示,但在实际设备上未正确显示 - ios9 - Xcode 7 - Swift - Keyboard shows correctly in Simulator but not on an actual Device iOS实际设备上的Appium出现SDK Iphone Simulator错误 - Appium on ios actual device gives sdk iphone simulator error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM