objective-c - 如何旋转嵌入UIWebView的视频(iOS 7)?
大家讲道理
大家讲道理 2017-04-22 08:59:48
0
1
624

我在开发的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)?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
阿神

Answer:
Denisia
I found the solution myself! Execute the following method in AppDelegate and it succeeds! My problem is that at the beginning, I didn't check the right 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
Try this:

-(BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

If you want to prevent the UIViewController from rotating when the screen does not display the video, use the following:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(webView && webView.superView) return YES;
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template