ios實(shí)現(xiàn)屏幕旋轉(zhuǎn)的方法

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)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末糠排,一起剝皮案震驚了整個(gè)濱河市舵稠,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌入宦,老刑警劉巖哺徊,帶你破解...
    沈念sama閱讀 218,284評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異乾闰,居然都是意外死亡落追,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門涯肩,熙熙樓的掌柜王于貴愁眉苦臉地迎上來轿钠,“玉大人,你說我怎么就攤上這事病苗∫ド牛” “怎么了?”我有些...
    開封第一講書人閱讀 164,614評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵铅乡,是天一觀的道長继谚。 經(jīng)常有香客問我,道長阵幸,這世上最難降的妖魔是什么花履? 我笑而不...
    開封第一講書人閱讀 58,671評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮挚赊,結(jié)果婚禮上诡壁,老公的妹妹穿的比我還像新娘。我一直安慰自己荠割,他們只是感情好妹卿,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,699評(píng)論 6 392
  • 文/花漫 我一把揭開白布旺矾。 她就那樣靜靜地躺著,像睡著了一般夺克。 火紅的嫁衣襯著肌膚如雪箕宙。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,562評(píng)論 1 305
  • 那天铺纽,我揣著相機(jī)與錄音,去河邊找鬼狡门。 笑死陷寝,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的其馏。 我是一名探鬼主播叛复,決...
    沈念sama閱讀 40,309評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼肤寝,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了耍群?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,223評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤找筝,失蹤者是張志新(化名)和其女友劉穎蹈垢,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體袖裕,經(jīng)...
    沈念sama閱讀 45,668評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡曹抬,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,859評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了急鳄。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片谤民。...
    茶點(diǎn)故事閱讀 39,981評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖疾宏,靈堂內(nèi)的尸體忽然破棺而出张足,到底是詐尸還是另有隱情,我是刑警寧澤坎藐,帶...
    沈念sama閱讀 35,705評(píng)論 5 347
  • 正文 年R本政府宣布为牍,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏碉咆。R本人自食惡果不足惜抖韩,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,310評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望吟逝。 院中可真熱鬧帽蝶,春花似錦、人聲如沸块攒。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽囱井。三九已至驹尼,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間庞呕,已是汗流浹背新翎。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評(píng)論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留住练,地道東北人地啰。 一個(gè)月前我還...
    沈念sama閱讀 48,146評(píng)論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像讲逛,于是被迫代替她去往敵國和親亏吝。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,933評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容