iOS設(shè)備旋轉(zhuǎn)(更新)

1 配置

//appDelegate,默認(rèn)是plist里面UIInterfaceOrientation決定(Build Settings->General設(shè)置)。
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
      //優(yōu)先級(jí)高于info.plist
}

系統(tǒng)沒有關(guān)閉自動(dòng)旋轉(zhuǎn)時(shí)

//UIViewController.m
#pragma mark - rotation
//定義是否支持自動(dòng)旋轉(zhuǎn)
-(BOOL)shouldAutorotate {
    return YES;
}
//定義支持旋轉(zhuǎn)的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return isPad ? UIInterfaceOrientationMaskLandscape : UIInterfaceOrientationMaskPortrait;
}
//定義第一次進(jìn)來的時(shí)候的方向
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return isPad ? UIInterfaceOrientationLandscapeLeft : UIInterfaceOrientationPortrait;
}

2 生命周期

//controller
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    if (size.width > size.height) {
        //橫屏設(shè)置,為防止遮擋鍵盤,調(diào)整輸入視圖的高度
        self.textView_height.constant = 50;
    }else{
        //豎屏設(shè)置
        self.textView_height.constant = 200;
    }
}

//子視圖
- (void)layoutSubviews {
    [super layoutSubviews];

    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationMaskPortrait) {
        //豎屏布局
    } else {
        //橫屏布局
    }
}

3 設(shè)備方向&屏顯方向

UIDeviceOrientation
機(jī)器硬件方向,只讀,可以通過KVC設(shè)置
    [UIDevice currentDevice].orientation
UIInterfaceOrientation
程序界面方向,屬性只讀,有set方法可寫。
    [UIApplication sharedApplication].statusBarOrientation

注意

  1. 注意彈框View與旋屏
  2. 橫豎屏分辨率數(shù)
//iOS 8之后
//    豎屏:  
    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)  
//    橫屏:  
    UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0) 

iOS橫豎屏旋轉(zhuǎn)及其基本適配方法

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • /* UIViewController is a generic controller base class th...
    DanDanC閱讀 2,035評(píng)論 0 2
  • 你可以問什么問題,能讓你和你的伴侶覺得自己是世界上最幸運(yùn)的人? 很多人都有愛情保鮮的秘訣,比如我知道龔琳娜老師喜歡...
    然媽Miya閱讀 362評(píng)論 0 4
  • 對(duì)句:天下見聞?dòng)^則廣【依嵐聽雪】 出句:世間學(xué)問悟?yàn)楦摺緰|方墨耕】 ———————————————---- 江山在...
    依嵐聽雪閱讀 467評(píng)論 0 1
  • 三國(guó)中有一個(gè)人絕對(duì)是大名鼎鼎的,不過這所謂的名聲不是什么好的名聲,而是惡名,暴名!正是因?yàn)樗某霈F(xiàn),漢朝延續(xù)了幾百...
    夕陽褪去時(shí)閱讀 632評(píng)論 0 1

友情鏈接更多精彩內(nèi)容