Safari會(huì)自動(dòng)進(jìn)入全局播放的情況
//禁止Safari自動(dòng)全屏播放 ?webView.allowsInlineMediaPlayback = YES;
iOS 全局禁止橫屏惊畏,但UIWebView 全屏播放視頻记某,橫屏舞丛,解決辦法
UIWebview在播放網(wǎng)頁視頻的時(shí)候我們需要進(jìn)行是否全屏狀態(tài)的監(jiān)聽。
一般的需求是在播放視頻時(shí)候需要橫屏脏里,退出全屏的時(shí)候不能橫屏她我,但是UIWebview沒有給出響應(yīng)的方法
1,在APPDelegate.h文件中增加屬性:是否支持橫屏
/***? 是否允許橫屏的標(biāo)記 */
@property (nonatomic,assign)BOOL allowRotation;
在APPDelegate.m文件中增加方法,控制全部不支持橫屏
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.allowRotation) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
2番舆,在需要實(shí)現(xiàn)webView橫屏的界面上添加通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(begainFullScreen) name:UIWindowDidBecomeVisibleNotification object:nil];//進(jìn)入全屏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endFullScreen) name:UIWindowDidBecomeHiddenNotification object:nil];//退出全屏
在退出全屏?xí)r酝碳,增加邏輯讓其強(qiáng)制編程豎屏,這樣當(dāng)全屏播放的時(shí)候恨狈,點(diǎn)擊down("完成")時(shí)疏哗,就會(huì)自動(dòng)變成豎屏了。
// 進(jìn)入全屏
-(void)begainFullScreen
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.allowRotation = YES;
}
// 退出全屏
-(void)endFullScreen
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.allowRotation = NO;
//強(qiáng)制歸正:
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val =UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}