用網(wǎng)頁播放器播放視頻時導(dǎo)航欄被頂上去了

iOS 全局禁止橫屏,但UIWebView 全屏播放視頻,橫屏,解決辦法

UIWebview在播放網(wǎng)頁視頻的時候我們需要進行是否全屏狀態(tài)的監(jiān)聽。

一般的需求是在播放視頻時候需要橫屏,退出全屏的時候不能橫屏,但是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;

}

這樣在其他界面想要橫屏的時候,我們只要控制allowRotation這個屬性就可以控制其他界面進行橫屏了。

//需在上面

#import "AppDelegate.h"AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

appDelegate.allowRotation = YES;//不讓橫屏的時候

appDelegate.allowRotation = NO;即可

2:播放界面橫屏:

2.3:播放界面橫屏:問題解決

所以這里可以使用UIWindow的通知,就可以解決

[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(begainFullScreen)name:UIWindowDidBecomeVisibleNotificationobject:nil];//進入全屏[[NSNotificationCenter defaultCenter]addObserver:selfselector:@selector(endFullScreen)name:UIWindowDidBecomeHiddenNotificationobject:nil];//退出全屏

在退出全屏?xí)r,增加邏輯讓其強制編程豎屏,這樣當(dāng)全屏播放的時候,點擊down("完成")時,就會自動變成豎屏了。

// 進入全屏

-(void)begainFullScreen{

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

appDelegate.allowRotation = YES;

}

// 退出全屏

-(void)endFullScreen{AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

appDelegate.allowRotation = NO;//強制歸正:

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];

}

self.navigationController.navigationBar.center = CGPointMake(screen_Width/2, 44);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容