關於設定iOS橫豎屏的兩種方式(轉載)

來源:互聯網
上載者:User

標籤:style   http   io   ar   os   使用   sp   for   on   

iPhone的橫屏豎屏針對iOS系統版本分為兩種開發方式: 一種是iOS 6之前的使用模式 一種是iOS6的新模式. 兩者的區別還是蠻大的.

1:iOS6之前通常使用 shouldAutorotateToInterfaceOrientation 來單獨控制某個UIViewController的方向,需要哪個viewController支援旋轉,只需要重寫shouldAutorotateToInterfaceOrientation方法。如下樣本,設定以後,螢幕被旋轉時只支援橫屏轉換:- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  {     return UIInterfaceOrientationIsLandscape(interfaceOrientation);  }    iOS6之後使用如下兩個方法控制自動旋轉,分別是:  - (BOOL)shouldAutorotate  {      NSLog(@"讓不讓我旋轉?");      return YES;  }  - (NSUInteger)supportedInterfaceOrientations {      NSLog(@"讓我旋轉哪些方向");      return UIInterfaceOrientationMaskAllButUpsideDown;  }    那麼在自動旋轉觸發後,系統會自動調用另外兩個方法:  - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {      [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];      NSLog(@"將要旋轉了?");  }  - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {      [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];      NSLog(@"如果讓我旋轉,我已經旋轉完了!");       }    2:讓程式第一次啟動時立刻顯示橫屏還是豎屏的方式如果是iOS6之前,下面設定的裝置支援方向可在應用裡面再被修改如果是iOS6以後,會做為硬性條件,也就是如果設定了以後,應用裡面的代碼也無法再使用這個方向  3:傳說中的私人API實現切換ViewController強制橫屏的方式if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {          [[UIDevice currentDevice] performSelector:@selector(setOrientation:)                                         withObject:(id)UIInterfaceOrientationLandscapeRight];      }   4:使用xib進行介面設計時,改變xib的橫豎顯示方式

關於設定iOS橫豎屏的兩種方式(轉載)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.