iOS中仅当视屏全屏播放时支持视屏旋转

开发环境:XCode7.2 

项目设置:Device Orientation仅勾选Portrait    Deployment Target7.0  使用MediaPlayer

需求:在视屏进入全屏播放时,视屏视图旋转,达到真的全屏播放

实现:①在AppDelegate.h文件中声明一个BOOL类型的变量,记录是否允许旋转:

             @property (nonatomic, assign) BOOL  allowRotation;

          ②在AppDelegate.m文件中添加方法内容:(方法为系统提供)

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

                       if(self.allowRotation) {

                               //无特殊要求,故直接返回支持所有方向旋转

                               return UIInterfaceOrientationMaskAll;

                      }else{

                    //当不允许旋转的时候,只支持默认的方向              

                               return UIInterfaceOrientationMaskPortrait;

                     }

           }

        ③在有播放器的viewController中导入AppDelegate

            #import"AppDelegate.h"

        ④添加观察者方法:(自己定义,定以后可在viewDidLoad中调用)

           - (void)addNotification {

                    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

                   [center addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];//进入全屏的通知

                  [center addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];//退出全屏的通知

}

- (void)willEnterFullScreen:(NSNotification*)notification

{

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

      //设置在进入全屏时,允许旋转

      delegate.allowRotation=YES;

}

- (void)willExitFullScreen:(NSNotification*)notification

{

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

     //设置退出全屏模式禁止旋转

      delegate.allowRotation=NO;

}

//释放观察者

- (void)dealloc {

      [[NSNotificationCenter defaultCenter] removeObserver:self];

}

通过以上方法达到了项目仅支持原始方向的竖屏,但当播放器进入全屏模式的时候,可以旋转播放器,使视频全屏播放

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值