iOS9橫屏豎屏設定

來源:互聯網
上載者:User

標籤:

公司App裡面有個需求,即所有介面都是豎屏,且不允許橫屏切換,唯專屬一個播放視頻的介面允許橫屏,大家都知道視頻播放適配最大的播放螢幕那樣是最好的。從網上多方尋找資料,查到了這麼一篇文章:
  1. 最終,根據此需求處理如下: 首先,確保App本身應該允許轉屏切換:

  2. 我的App裡面UITabBarController是根視圖控制器,所以首先建立一個UITabBarController的子類,並設定允許轉屏:
    (這些要放在根視圖控制器裡面, 如果你的應用根視圖是UINavigationController, 就放在那裡面就好)

#pragma mark 轉屏方法重寫-(UIInterfaceOrientationMask)supportedInterfaceOrientations{    return [self.viewControllers.firstObject supportedInterfaceOrientations];}-(BOOL)shouldAutorotate{    return self.viewControllers.firstObject.shouldAutorotate;}
  1. 接著,我的tabbarController裡面每個子控制器又都是UINavigationController進行介面push切換的,所以首先建立一個UINavigationController的子類,並設定允許轉屏:
//self.topViewController是當前置航顯示的UIViewController,這樣就可以控制每個UIViewController所支援的方向啦!-(BOOL)shouldAutorotate{    return [self.topViewController shouldAutorotate];}- (UIInterfaceOrientationMask)supportedInterfaceOrientations {    return [self.topViewController supportedInterfaceOrientations];}
  1. 在你想轉屏切換的ViewController上可以照這樣重寫(允許左右橫屏以及豎屏):
- (BOOL)shouldAutorotate {    return NO;}- (UIInterfaceOrientationMask)supportedInterfaceOrientations {    return UIInterfaceOrientationMaskPortrait;}
  1. 到視頻播放介面要設定為橫屏啦(我的視訊播放只要橫屏就好^_^)
// 是否支援旋轉螢幕- (BOOL)shouldAutorotate {    return NO;}- (UIInterfaceOrientationMask)supportedInterfaceOrientations {    return UIInterfaceOrientationMaskLandscape;}-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    return UIInterfaceOrientationLandscapeRight;}

注意:跳轉到播放器要使用模態進來, 用Push會報錯
[self presentViewController:playerVC animated:YES completion:nil];

iOS9橫屏豎屏設定

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.