屏幕旋转设置

在做视频的时候需要视频所在的页面可以横屏,但是整个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];
        
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,651评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,747评论 4 61
  • 娜娜是从农村来到城市学习理发手艺的,由于父母提前找了亲戚,所以在亲戚旁边的理发店实习,而亲戚的女主人对娜娜总是不理...
    我是岸阅读 1,567评论 0 1
  • 今天是老公的生日,想想在一起整整一十二年,一个轮回了。 她给睡在左边的孩子掖掖被角,亲亲红扑扑的小脸蛋儿,多可爱呀...
    思无邪的世界阅读 3,184评论 0 32
  • 课程任务 1.样式有几种引入方式? link 和 @import有什么区别? 答: 外部样式表:将css的样式代码...
    呦泥酷阅读 1,621评论 0 0

友情链接更多精彩内容