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

2024-04-09

在我的应用程序中,我一直在使用现已弃用的 shouldAutoRotateToFace 方法。现在,当使用 iOS 6 模拟器时,当设备处于横向时,我的所有子视图都会旋转到纵向。有谁知道这可能是什么原因造成的?我已经尝试使用supportedOrientations方法(或者您现在应该使用的任何方法)替换主视图控制器中的should autorotate。


如果您可以登录 Apple 开发论坛,看看这个线程 https://devforums.apple.com/message/727235.

基本上,这是对我有帮助的信息:


1.我必须设置window.rootViewController = mainViewController in

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

2.对于视图控制器,其中

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation

didn't就回来YES,我必须添加

- (NSUInteger)supportedInterfaceOrientations

返回相同的值

3. Added

- (BOOL)shouldAutorotate {
    return YES;
}

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

到 mainViewController.m

4. Added

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

appDelegate.m(我相信这是可选的,用于设置默认值,以防应用程序的 Info.plist 文件或单个视图控制器中未指定它们)



因为我希望我的代码向后兼容回 3.0,所以我没有使用All方向掩码,因为我需要使用 XCode 4.3 进行编译

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS 6 中视图控制器的旋转不正确 的相关文章

随机推荐