IOS 6: Youtube embed video (MPAVController) in browser can block application in landscape mode

I embed a Youtube video in a browser that is part of all portraits. When you run a youtube video, it plays in the MPAVController and rotation is allowed in Landscape. This is not a problem for me, but the problem is that the video is in the landscape, and I click "OK" to cancel the video; I will return to the browser, but the iPhone status bar is now stuck in landscape mode, leaving an empty space at the top of the application, as well as in the status bar that overlaps the right or left side of my application depending on the orientation of rotation.

The My view controller containing the UIWebView is locked in the portrait:

- (BOOL) shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; } 

Please note that this problem is missing when compiling with SDKs up to 6.0.

Anyone with a similar problem have a solution?

+4
source share
2 answers

I ran into the same problem. Here's how I solved it:

First, register to receive ExitFullscreenNotification, on a ViewController that contains a UIWebView:

 - (void)viewDidLoad { [super viewDidLoad]; // For FullSCreen Exit [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeVideoExit:) name:@"UIMoviePlayerControllerDidExitFullscreenNotification" object:nil]; } 

Then, in the "exit fullscreen" handler, forcibly select Portrait mode:

 - (void)youTubeVideoExit:(id)sender { [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; } 

When the video ends in landscape mode, the user sees that the status bar changes its location for a split second. This may not be the best solution, but at least it solves the problem.

Hope this helps!

+5
source

Turns out my look was built into the UINavigationController, so I needed to handle my rotation there.

I created a category and posted a rotation code there

UINavigationController + Autorotate.m

 #import "UINavigationController+Autorotate.h" @implementation UINavigationController (Autorotate) - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } @end 

UINavigationController + Autorotate.h

 #import <UIKit/UIKit.h> @interface UINavigationController (Autorotate) - (NSUInteger)supportedInterfaceOrientations; @end 
0
source

Source: https://habr.com/ru/post/1438740/


All Articles