iOS - 視頻播放處理全屏/橫屏時候遇見的坑

來源:互聯網
上載者:User

標籤:設定   播放   elf   ack   har   ide   iap   oid   自己   

 

   視頻播放想要全屏,使用shouldAutorotate方法禁止主介面,tabbar控制器橫屏,導致push進入播放頁面不能橫屏的問題。。。

 

- (BOOL)shouldAutorotate {

    return NO;

}

 

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskAll;

}

 

後面解決方案:

- (void)fullScreenClick:(UIButton *)sender {

    sender.selected = !sender.selected;

    if (sender.isSelected) {

        _backButton.hidden = YES;

        [self forceOrientationLandscapeLeft];

    } else {

        _backButton.hidden = NO;

        [self forceOrientationPortrait];

    }

}

 

//MARK: -- 強制橫屏

- (void)forceOrientationLandscapeLeft

{

    AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;

    appdelegate.isForcePortrait=NO;

    appdelegate.isForceLandscape=YES;

    [appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];

    

    YNCNavigationViewController *navi = (YNCNavigationViewController *)self.navigationController;

    navi.interfaceOrientation = UIInterfaceOrientationMaskLandscape;

    navi.interfaceOrientationMask = UIInterfaceOrientationMaskLandscape;

    

    //設定螢幕的轉向為橫屏

    [[UIDevice currentDevice] setValue:@(UIDeviceOrientationLandscapeLeft) forKey:@"orientation"];

    //重新整理

    [UIViewController attemptRotationToDeviceOrientation];

}

 

//MARK: -- 強制豎屏

- (void)forceOrientationPortrait

{

    AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;

    appdelegate.isForcePortrait=YES;

    appdelegate.isForceLandscape=NO;

    [appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:self.view.window];

    

    YNCNavigationViewController *navi = (YNCNavigationViewController *)self.navigationController;

    navi.interfaceOrientation = UIInterfaceOrientationPortrait;

    navi.interfaceOrientationMask = UIInterfaceOrientationMaskPortrait;

    

    //設定螢幕的轉向為豎屏

    [[UIDevice currentDevice] setValue:@(UIDeviceOrientationPortrait) forKey:@"orientation"];

    //重新整理

    [UIViewController attemptRotationToDeviceOrientation];

}

 

#import <UIKit/UIKit.h>

 

@interface AppDelegate : UIResponder <UIApplicationDelegate>

 

@property (strong, nonatomic) UIWindow *window;

 

@property (assign , nonatomic) BOOL isForceLandscape;

@property (assign , nonatomic) BOOL isForcePortrait;

 

@end

AppDelegate.m

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    if (self.isForceLandscape) {

        return UIInterfaceOrientationMaskLandscape;

    }else if (self.isForcePortrait){

        return UIInterfaceOrientationMaskPortrait;

    }

    return UIInterfaceOrientationMaskPortrait;

}

 

@interface YNCNavigationViewController : UINavigationController

 

//旋轉方向 預設豎屏

@property (nonatomic , assign) UIInterfaceOrientation interfaceOrientation;

@property (nonatomic , assign) UIInterfaceOrientationMask interfaceOrientationMask;

 

@end

 

.m

#pragma mark - 由子控制器控制自己的轉屏邏輯

- (BOOL)shouldAutorotate {

    return YES;

}

 

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

    return self.interfaceOrientationMask;

}

 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    return self.interfaceOrientation;

}

 

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.