Rotation and multiple windows

I am creating a video player that controls full screen mode in an attempt to emulate the behavior MPMoviePlayerController

. In fact, when you press the full screen button, the player view moves to a different instance UIWindow

.
Immediately after clicking the button, the code creates a c window rootViewController

that hosts the player's view.
The app can only control the portrait orientation, but the view controller that places the player in a new window is landscape only.
Everything works great: if I click full screen, the simulator rotates in landscape orientation, showing the player in full screen mode.
The problem comes when I want the application to return on normal rendering, the window disappears and returns to "application", the problem is that the status bar remains in the terrain.
Nothing works on iOS8, but that's another story.
App view controllers are configured to support portrait only:

- (BOOL)shouldAutorotate
{
    return YES;
}


- (NSUInteger)supportedInterfaceOrientations
{
    NSUInteger orietationMask = 0;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        orietationMask = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
    }
    else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        orietationMask = (UIInterfaceOrientationMaskPortrait);
    }
    return orietationMask;
}

      

Only the view manager, which will place the player view in another window, is set to support only the landscape.

- (BOOL)shouldAutorotate
{
    return YES;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}

- (NSUInteger)supportedInterfaceOrientations
{
    NSUInteger orietationMask = 0;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        orietationMask = (UIInterfaceOrientationMaskLandscape);
    }
    else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        orietationMask = (UIInterfaceOrientationMaskLandscape )  ;

    }
    return orietationMask;
}

      

Here is a quick summary of the methods I use to create a window and view the swap:

- (void) createWindow {
    self.playerWindow = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]] ;
    self.playerWindow.windowLevel = UIWindowLevelNormal;
    self.fullScreenViewController = [[FullScreenPlayerViewController alloc] init];
    self.playerWindow.rootViewController = self.fullScreenViewController;
}

- (void) swapPlayerViewHost {
    self.oldHostingView = self.playerView.superview;
    UIView * playerView = self.playerView;
    [playerView removeFromSuperview];
    [self.fullScreenViewController.view addSubview:playerView];
    playerView.frame = self.fullScreenViewController.bounds;

}
- (void) restorePlayerViewPosition {
    UIView * playerView = self.playerView;
    [playerView removeFromSuperview];
    [self.oldHostingView addSubview:playerView];
    playerView.frame = self.oldHostingView.bounds;
    [self.oldWindow makeKeyAndVisible];
    self.playerWindow.hidden = YES;
    self.oldHostingView = nil;
    self.playerWindow = nil;
}

#pragma mark -
#pragma mark Movie controller methods


- (void) setFullScreen:(BOOL) fullScreen {
    if (fullScreen) {
        // Create window
        [self createWindow];
        // Swap player view
        [self swapPlayerViewHost];
        // Make view visible
        [self.playerWindow makeKeyAndVisible];
        _fullScreen = YES;
    }
    else {
        [self restorePlayerViewPosition];
        _fullScreen = NO;
    }

}

      

+3


source to share