问题
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