UIInterfaceOrientation over iOS6 (应用旋转屏幕)
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft };
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape; }
#import "TYSXTabBarController.h" #define kTabBarColor [UIColor colorWithRed:0.953f green:0.953f blue:0.953f alpha:1.00f] #define kTintColor [UIColor colorWithRed:0.914f green:0.000f blue:0.294f alpha:1.00f] @implementation TYSXTabBarController - (void)viewDidLoad { [super viewDidLoad]; self.tabBar.translucent = NO; [self.tabBar setBarTintColor:kTabBarColor]; self.tabBar.tintColor = kTintColor; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (BOOL)shouldAutorotate { return YES; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } @end
这样,TabBarController下的所有页面就都只能是竖向了。
如何让某个页面只能是横向的呢?
以全屏播放页面(FullScreenViewController)为例,Present显示该页面,如此,播放页面就与TabBarController独立开了,在FullScreenViewController.m中实现以下方法
@implementation FullScreenViewController - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); } @end
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。