iOS中仅当视屏全屏播放时支持视屏旋转
2016-03-30 14:50
417 查看
开发环境: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{
//当不允许旋转的时候,只支持默认的方向
4000
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];
}
通过以上方法达到了项目仅支持原始方向的竖屏,但当播放器进入全屏模式的时候,可以旋转播放器,使视频全屏播放
项目设置: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{
//当不允许旋转的时候,只支持默认的方向
4000
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];
}
通过以上方法达到了项目仅支持原始方向的竖屏,但当播放器进入全屏模式的时候,可以旋转播放器,使视频全屏播放
相关文章推荐
- iOS开发——modifying the autolayout engine from a background thread
- 详解iOS应用开发中使用设计模式中的抽象工厂模式
- IOS蓝牙4.0使用心得
- 整理苹果官网上iOS的各种辅助功能
- RevealiOS使用教程之简易配置:不修改您的Xcode工程并加载Reveal
- iOS之9.3真机适配-Could not find Developer Disk Image问题
- 实例解析设计模式中的外观模式在iOS App开发中的运用
- 整理常用iOS的第三方框架
- Windows7上使用VMWare搭建IOS开发环境
- 你真的了解iOS代理设计模式吗?
- iOS Provisioning Profile(Certificate)与Code Signing详解
- iOS扩展是指与一些热门或常见的范例
- iOS开发之解析XML数据
- iOS沙盒清除缓存
- iOS9 访问通讯录
- IOS-59-解决错误:linker command failed with exit code 1 (use -v to see invocation)
- iOS quartzCore第三章——CAEmitterLayer和CAEmitterCell详解
- 设计模式开发中的备忘录模式在iOS应用开发中的运用实例
- IOS caf音频文件如何转化成mp3文件
- 深入解析设计模式中的装饰器模式在iOS应用开发中的实现