MPInlineVideoFullscreenViewController and AVFullScreenViewController first appear in portrait mode

Too many landscape related issues in MPMovieplayer. My application is in portrait mode. But I want a video in landscape mode. I already have a landscape / portrait function for the video. I am using the following code:

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
    [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{

    return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
    return UIInterfaceOrientationMaskPortrait;
}

}

The code works fine in both iOS 7 and iOS8. But the problem is that the video first opens in portrait mode when the device is in landscape mode. After changing the orientation, than the application is working fine.

Thanks in advance.

+4
source share
1 answer

R & D 2-3 . , . , .

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
[[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{
  return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;

}

, UIWebView . , ViewController UINavigationController, , ViewController.

-(BOOL)shouldAutorotate;  
-(NSUInteger)supportedInterfaceOrientations;

, ViewDidLoad

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

viewWillDisappear

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

, , .

, .

+2

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


All Articles