iOS UIWebView 全屏播放视频横屏 app其他页面不支持横屏

来源:互联网 发布:中国铁矿石进口数据 编辑:程序博客网 时间:2024/05/19 17:03


1,类似qq空间里面的视频,点击播放过后,如果手机开启了旋转功能,那么旋转的时候,视频也旋转。


首先,要想横屏,先打开手机的横屏开关键,如图点击查看图片

然后设置整个项目的Device Orientation 如图所示:


接下来就是代码的事情了,在AppDelegate.h里面声明一个变量isFull

@property (nonatomic)BOOL isFull;

在AppDelegate.m里面写此方法

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{    if(_isFull) return UIInterfaceOrientationMaskAll;//可以旋转    return UIInterfaceOrientationMaskPortrait;//只竖屏}


在你的UIWebViewControler.m里面

首先引入AppDelegate 

#import "AppDelegate.h"

定义一个局部变量

AppDelegate *_appDelegate;

然后加入代码

#pragma mark 设置程序可以旋转- (void)videoStarted:(NSNotification *)notification {// 开始播放    _appDelegate.isFull = YES;}#pragma mark 设置程序不能旋转- (void)videoFinished:(NSNotification *)notification {// 开始播放     _appDelegate.isFull = NO;}- (void)viewDidLoad {    [super viewDidLoad];        _appDelegate = [[UIApplication sharedApplication] delegate];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStarted:) name:UIWindowDidBecomeVisibleNotification object:nil];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoFinished:) name:UIWindowDidBecomeHiddenNotification object:nil];}


ok,done!


2.类似微信朋友圈里面网页点击进去播放视频,进入网页那个Controler就可以横屏


只需要在UIWebViewControler页面的viewDidLoad方法里面设置_appDelegate.isFull = YES;在viewWillDisappear方法里面设置_appDelegate.isFull = NO;就可以了


1 0
原创粉丝点击