屏幕旋轉設置

在做視頻的時候需要視頻所在的頁面可以橫屏,但是整個APP中其他頁面都是不允許橫屏的,這個時候要怎么做呢?

AppDelegate.h
@property (nonatomic, assign) BOOL allowRotation;
AppDelegate.m
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  {

    if (self.allowRotation) {
        return UIInterfaceOrientationMaskPortrait|
        UIInterfaceOrientationMaskLandscapeLeft|
        UIInterfaceOrientationMaskLandscapeRight;
    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}
視頻詳情頁:
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    SET_UIStatusBarStyleLightContent;
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    // 允許橫屏操作
    [(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:YES];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (_needInputTime) {
        [self inputPlayTime];
    }
    
    // 禁止橫屏操作
    [(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:NO];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        
        SEL selector = NSSelectorFromString(@"setOrientation:");
        
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        
        [invocation setSelector:selector];
        
        [invocation setTarget:[UIDevice currentDevice]];
        
        int val = UIInterfaceOrientationPortrait;
        
        [invocation setArgument:&val atIndex:2];
        
        [invocation invoke];
        
    }
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,436評論 25 708
  • 發現 關注 消息 iOS 第三方庫、插件、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,246評論 4 61
  • 娜娜是從農村來到城市學習理發手藝的,由于父母提前找了親戚,所以在親戚旁邊的理發店實習,而親戚的女主人對娜娜總是不理...
    我是岸閱讀 195評論 0 1
  • 今天是老公的生日,想想在一起整整一十二年,一個輪回了。 她給睡在左邊的孩子掖掖被角,親親紅撲撲的小臉蛋兒,多可愛呀...
    思無邪的世界閱讀 401評論 0 32
  • 課程任務 1.樣式有幾種引入方式? link 和 @import有什么區別? 答: 外部樣式表:將css的樣式代碼...
    呦泥酷閱讀 212評論 0 0