zoukankan      html  css  js  c++  java
  • iOS设置竖屏,播放视频可以任性旋转的解决方法,亲测可用

      之前在网上找了很多方法,都是强制横屏,但是如果设备关闭旋转锁定,强制横屏后把设备竖立起来,播放器也会跟着竖过来,但是就回不去了。现在项目要求让app默认都是竖屏,只有在全屏播放的时候可以自由旋转,于是在找了很多资料后茅塞顿开,具体思路就是设置app全局支持的设备方向为全部支持,然后针对每个控制器单独设置支持方向(这里可以写个分类),iOS会自动取全局和当前控制器的支持方向交集,所以只需要两部简单操作即可:

    1.在AppDelegate.m文件中添加以下代码

    /**
     *  设置全局支持方向,然后在控制器中单独配置各自的支持方向
     */
    - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        return UIInterfaceOrientationMaskAll;
    }

    2.添加分类UIViewController+Category.m

    -(UIInterfaceOrientationMask)supportedInterfaceOrientations
    {
        //设置只允许视频播放界面可以旋转,其他只能竖屏
        if ([self isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
            return UIInterfaceOrientationMaskAll;
        }else{
            return UIInterfaceOrientationMaskPortrait;
        }
    }

    但这样还有个小问题,就是在退出全屏的时候状态栏消失了,这里暂时还是用的退出全屏的通知,在收到通知后重新设置下显示状态栏

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endFullScreen) name:UIWindowDidBecomeHiddenNotification object:nil];//退出全屏
    
    // 退出全屏
    -(void)endFullScreen {
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }

    欢迎大家对以上方法指正,谢谢~

  • 相关阅读:
    解决SecureCRT中文显示乱码
    Linux命令: chown
    secureCRT登录不上ubuntu,Connection closed
    another app is currently holding the yum lock;waiting for it to exit解决
    分析一个socket通信: server/client
    Centos配置国内yum源
    liteos CPU占用率(十六)
    ft6236 触摸屏驱动
    Multi-touch (MT) Protocol 小结
    liteos 异常接管(十五)
  • 原文地址:https://www.cnblogs.com/huzhenchao/p/6908320.html
Copyright © 2011-2022 走看看