问题解决:iOS6下UIWebView嵌vedio标签播放视频屏幕不旋转
来源:互联网 发布:经典算法详解 编辑:程序博客网 时间:2024/05/22 15:06
项目默认为竖屏,在iOS6下UIWebView嵌Vedio标签播放视频屏幕不旋转,iOS5没有问题。
一、版本判断宏
// iOS版本===#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)// ===iOS版本
#pragma mark - Rotation// IOS5支持的屏幕方向- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}// IOS6开启旋转- (BOOL)shouldAutorotate { return YES;}// IOS6支持的屏幕方向- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown;}// IOS6默认支持竖屏- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait;}三、接着,为了解决iOS6下点击UIWebView中vedio标签,播放器可以不旋转的问题,需要注册播放器进入全屏和退出全屏的通知
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6")) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vedioStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];// 播放器即将播放通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vedioFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];// 播放器即将退出通知 }
四、再接着,通知事件处理,手工旋转屏幕,播放设为横屏左,退出设为竖屏——这里使用了私有api,有审核不过风险。
- (void)vedioStarted:(NSNotification *)notification {// 播放器即将播放处理 [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)UIDeviceOrientationLandscapeLeft];// iOS6只能选择一个横屏方向,暂时实现不了检测屏幕旋转而旋转}- (void)vedioFinished:(NSNotification *)notification {// 视频 [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)UIDeviceOrientationPortrait];// 屏幕方向回复默认的竖屏}
五、最后,记得移除通知的观察者
- (void)dealloc { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6")) { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil]; }}
参考:http://www.cocoachina.com/bbs/read.php?tid=137339&keyword=UIWebView%7Cvideo和http://stackoverflow.com/a/8554040/966127
完整代码:里面用到UIWebView开源浏览器SVWebViewController(下载地址:https://github.com/samvermette/SVWebViewController)
BLWebVC.h
#import <UIKit/UIKit.h>@class SVWebViewController;@interface BLWebVC : UINavigationController- (id)initWithAddress:(NSString*)urlString;- (id)initWithURL:(NSURL *)URL;@property (nonatomic, retain) UIColor *barsTintColor;@end
BLWebVC.m
//// BLWebVC.m// XXX//// Created by yhw on 13-3-29.////#import "BLWebVC.h"#import "SVWebViewController.h"@interface BLWebVC ()@property (nonatomic, retain) SVWebViewController *webViewController;@end@implementation BLWebVC- (void)dealloc { if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6")) { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil]; } [_barsTintColor release]; // [_webViewController release]; [super dealloc];}- (void)loadView { [super loadView]; //// self.view.backgroundColor = [UIColor whiteColor];}- (void)viewDidLoad{ if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6")) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vedioStarted:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];// 播放器即将播放通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vedioFinished:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil];// 播放器即将退出通知 }}- (void)vedioStarted:(NSNotification *)notification {// 播放器即将播放处理 [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)UIDeviceOrientationLandscapeLeft];// iOS6只能选择一个横屏方向,暂时实现不了检测屏幕旋转而旋转}- (void)vedioFinished:(NSNotification *)notification {// 视频 [[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)UIDeviceOrientationPortrait];// 屏幕方向回复默认的竖屏}#pragma mark - Initialization- (id)initWithAddress:(NSString*)urlString { return [self initWithURL:[NSURL URLWithString:urlString]];}- (id)initWithURL:(NSURL *)URL { self.webViewController = [[[SVWebViewController alloc] initWithURL:URL] autorelease]; if (self = [super initWithRootViewController:self.webViewController]) { self.webViewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:webViewController action:@selector(doneButtonClicked:)] autorelease]; } return self;}#pragma mark - Setters- (void)setBarsTintColor:(UIColor *)barsTintColor { if (_barsTintColor != barsTintColor) { [_barsTintColor release]; _barsTintColor = [barsTintColor retain]; } self.navigationBar.tintColor = _barsTintColor;}#pragma mark - Rotation// IOS5支持的屏幕方向- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);}// IOS6开启旋转- (BOOL)shouldAutorotate { return YES;}// IOS6支持的屏幕方向- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown;}// IOS6默认支持竖屏- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait;}- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];}- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];}- (void)handleOrientationChangeNotification:(NSNotification *)notification{ }@end
- 问题解决:iOS6下UIWebView嵌vedio标签播放视频屏幕不旋转
- UIWebView中视频播放屏幕自动旋转,app不支持旋转但是某一个页面需要旋转等
- UIWebView中视频播放屏幕自动旋转,app不支持旋转但是某一个页面需要旋转等
- 视频播放屏幕旋转
- 问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6
- 问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6
- Vedio.js视频播放
- iOS6下屏幕旋转不响应以及使用Three20不旋转解决方案
- iOS6下屏幕旋转不响应以及使用Three20不旋转解决方案
- iOS6屏幕旋转
- iOS6屏幕旋转
- IOS6屏幕旋转
- ios6 屏幕旋转总结
- iOS6屏幕旋转
- IOS6屏幕旋转问题
- 关于IOS6屏幕旋转
- ios6 屏幕旋转问题
- ios6 屏幕旋转
- 获取从当年当月起往前推12个月的某年某月的下拉框(JS+JQUERY)
- Java开发中容易被忽视的东西
- C++的输出精度控制(转)
- QT 编译错误 multiple definition of
- Common Subsequence
- 问题解决:iOS6下UIWebView嵌vedio标签播放视频屏幕不旋转
- ubuntu开机进入命令行界面
- Lua基础 generic for
- 逆康拓展开
- 黑马程序员java基础篇----面向对象总结(上)
- Proteus和Keil的使用与联调
- hdu 2092 整数解
- 异常
- SecureCRT连接ubuntu