objective-c - 如何旋轉嵌入UIWebView的影片(iOS 7)?
大家讲道理
大家讲道理 2017-04-22 08:59:48
0
1
663

我在開發的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);
}
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板