简体   繁体   English

iOS 6中视图控制器的旋转不正确

[英]Incorrect rotation of a view controller in iOS 6

In my app I've been using the now deprecated shouldAutoRotateToFace method. 在我的应用程序中,我一直在使用现在不建议使用的shouldAutoRotateToFace方法。 Now when using the iOS 6 simulator, all of my subviews are rotated to portrait orientation while the device is in landscape. 现在,当使用iOS 6模拟器时,设备处于横向时,我的所有子视图都将旋转为纵向。 Does anyone have any idea what could cause this? 有谁知道是什么原因引起的? I've already tried replacing should autorotate in my main view controller with the supportedOrientations method (or whatever it is that you're now supposed to use instead). 我已经尝试过使用supportedOrientations方法(或现在应该使用的替代方法)替换应在主视图控制器中自动旋转的内容。

If you can log in to the Apple dev forums, check out this thread . 如果您可以登录到Apple开发者论坛, 请查看此线程

Basically, this is the information that helped me: 基本上,这是对我有帮助的信息:


1. I had to set window.rootViewController = mainViewController in 1.我必须在以下位置设置window.rootViewController = mainViewController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2. For view controllers where 2.对于视图控制器,

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation

didn't just return YES , I had to add 只是返回YES ,我不得不添加

- (NSUInteger)supportedInterfaceOrientations

that returned the same value 返回相同的值

3. Added 3.新增

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}

to mainViewController.m 到mainViewController.m

4. Added 4.新增

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
            UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown);
}

to appDelegate.m (I believe this is optional, for setting default values in case they're not specified in the app's Info.plist file, or in individual view controllers) 到appDelegate.m(我相信这是可选的,以防在应用的Info.plist文件或单个视图控制器中未指定默认值的情况下设置默认值)



Since I want my code backwards compatible back to 3.0 I didn't use the All orientation masks, as I need to compile using XCode 4.3 因为我希望代码向后兼容到3.0,所以我没有使用所有方向的掩码,因为我需要使用XCode 4.3进行编译

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM