1叁征、屏蔽AppDelegate下面的屏幕旋轉(zhuǎn)方法
#pragma mark - 屏幕旋轉(zhuǎn)的
//-(UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window {
// return UIInterfaceOrientationMaskPortrait;
//}````
2家破、對(duì)UINavigationController和UITabBarController寫兩個(gè)擴(kuò)展類別屹篓,此東西不需要在具體的ViewController中引用
UINavigationController+Autorotate.h
````//
// UINavigationController+Autorotate.h
// fitmiss
//
// Created by bill on 15/12/16.
// Copyright ? 2015年 lear. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UINavigationController (Autorotate)
@end````
UINavigationController+Autorotate.m
````//
// UINavigationController+Autorotate.m
// fitmiss
//
// Created by bill on 15/12/16.
// Copyright ? 2015年 lear. All rights reserved.
//
#import "UINavigationController+Autorotate.h"
@implementation UINavigationController (Autorotate)
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
@end````
UITabBarController+Autorotate.h
````//
// UITabBarController+Autorotate.h
// fitmiss
//
// Created by bill on 15/12/16.
// Copyright ? 2015年 lear. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITabBarController (Autorotate)
@end````
UITabBarController+Autorotate.m
````//
// UITabBarController+Autorotate.m
// fitmiss
//
// Created by bill on 15/12/16.
// Copyright ? 2015年 lear. All rights reserved.
//
#import "UITabBarController+Autorotate.h"
@implementation UITabBarController (Autorotate)
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
@end````
3.在使用的ViewController中的再次重寫這三個(gè)方法,可以在根ViewController中重寫如下方法混巧,就能實(shí)現(xiàn)豎屏细睡,子ViewController再重寫實(shí)現(xiàn)旋轉(zhuǎn)
- (BOOL)shouldAutorotate {
//是否允許轉(zhuǎn)屏
return NO;
} - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
//viewController所支持的全部旋轉(zhuǎn)方向
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
} - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ //viewController初始顯示的方向
return UIInterfaceOrientationPortrait;
}
注意:在使用的時(shí)候發(fā)現(xiàn)在ios9以下的版本出現(xiàn)一個(gè)奇怪的問題,就是編譯出來的app默認(rèn)是橫的忍宋,解決辦法是看app.plist下面Supported interface orientations里的列表中痕貌,正屏的是不是排在第一個(gè)。
[轉(zhuǎn)自:http://www.cnblogs.com/lear/p/5051818.html](http://www.cnblogs.com/lear/p/5051818.html)