objective-c - 如何旋轉嵌入UIWebView的視頻(iOS 7)?
問題描述
我在開發的APP是面向肖像的,但是當運行視頻(內嵌在webview)的時候,我需要在風景模式下重新定位視頻。應該怎么解決這一問題呢?我找到了一種解決方案,似乎可以解決問題。我覺得這是因為iOS 7的更新,但是我不確定。所以,這是我先前使用的,但是現在不起作用了,因為窗口和類名總是nil。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{id presentedViewController = [window.rootViewController presentedViewController];NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil;if (window && [className isEqualToString:@'MPInlineVideoFullscreenViewController']) { return UIInterfaceOrientationMaskAll;} else { return UIInterfaceOrientationMaskPortrait;}
原問題:How to rotate a video embed in UIWebView (for iOS 7 only)?
問題解答
回答1:答案:Denisia我自己找到了解決方法!在AppDelegate中執行如下方法,成功了!我的問題是,開始的時候,我沒有檢查右視圖控制器(view controller)。
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {NSString *className = NSStringFromClass([window class]);if ([((UINavigationController *)window.rootViewController) respondsToSelector:@selector(visibleViewController)]) { className = NSStringFromClass([((UINavigationController *)window.rootViewController).visibleViewController class]);}if ([className isEqualToString:@'MPFullscreenWindow'] || [className isEqualToString:@'MPInlineVideoFullscreenViewController']) { return UIInterfaceOrientationMaskAll;} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ return UIInterfaceOrientationMaskLandscape;} else { return UIInterfaceOrientationMaskPortrait;}
Immi試試這個:
-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation{return YES;}
如果你想在屏幕不顯示視頻的時候,不讓UIViewController旋轉,就使用下面的:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{if(webView && webView.superView) return YES;return UIInterfaceOrientationIsPortrait(interfaceOrientation);}
相關文章:
1. 前端 - node vue webpack項目文件結構2. 如何分別在Windows下用Winform項模板+C#,在MacOSX下用Cocos Application項目模板+Objective-C實現一個制作游戲的空的黑窗口?3. html5和Flash對抗是什么情況?4. php如何獲取訪問者路由器的mac地址5. javascript - 在 vue里面用import引入js文件,結果為undefined6. Java反射問題:為什么android.os.Message的recycleUnchecked方法不能通過反射獲取到?7. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現8. python - linux怎么在每天的凌晨2點執行一次這個log.py文件9. javascript - vue-resource中如何設置全局的timeout?10. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙
