in iOS7 how do you stop the First viewcontroller autorotating?

荒凉一梦 提交于 2019-12-13 00:06:51

问题


I have an app that just needs one screen to autorotate, the first and last screens should be portrait. I can get the last screen to stop rotating using:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

But this does not work on the first screen, I am using a storyboard with a UINavigationController (I'm thinking that may have something to do with it?)

Any help would be gratefully received. Thanks


回答1:


you may need to subset the UINavigationController and you should use it instead of the standard UINavigationController.

I have done this in my projects, so this cares of the individual UIViewController classes' custom orientations:

.h

#import <UIKit/UIKit.h>

@interface UIOrientationController : UINavigationController { }
@end

.m

@implementation UIOrientationController

- (BOOL)shouldAutorotate {
    return [self.topViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations {
    return [self.topViewController supportedInterfaceOrientations];
}

@end

NOTE: you can extended this class with overriding more methods, if it becomes a requirement in your final code.



来源:https://stackoverflow.com/questions/24239641/in-ios7-how-do-you-stop-the-first-viewcontroller-autorotating

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!