Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rotate a video embed in UIWebView (for iOS 7 only)?

The app I'm working on is portrait oriented, but when a video is running (it is embed in a webview), I need to re-orient the video in landscape mode. How should I do that? I found a solution, which worked just fine until days ago :). I believe it's because iOS 7 updates, but I'm not sure. So, this is what I previously used, but it is not working anymore because window and class name are always 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;
}
like image 922
Denisia Avatar asked Feb 28 '14 13:02

Denisia


1 Answers

I found a solution by myself, finally! I implemented the following method in AppDelegate and it worked. My problem was that, at first, 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;
} 
like image 134
Denisia Avatar answered Sep 30 '22 02:09

Denisia