Search code examples
iosfullscreenavplayeravplayerlayer

iOS 7 (sublayer) AVPlayer Fullscreen animate and need to above (cover) UINavigationBar


I am trying to give up MPMoviePlayerController and switch to AVPlayer but facing problem on 'AVPlayer(Layer) Full Screen animation'.

Project Source Code: http://www.kevin-and-idea.com/avplayer.zip

Goal: Currently, AVPlayer(Layer) is part of the elements on ViewController. The play is need to be able to switch between 'Small' and full screen and when it full screen, it need to be above (cover) statue bar and navigation bar. Also, the player need to be rotate-able depends on Device Orientation

Problem: Don't know how to 'take out' the AVPlayerLayer and 'Cover' the whole screen including statue bar & navigation bar.

Currently: I set UINavigationBar hide and status bar hide to archive but this is not the goal and rotate without issue

THANK YOU SO MUCH!!!

p.s. Click the info icon to switch to full screen https://c1.staticflickr.com/1/388/18237765479_7d3c292449_z.jpg

Code

- (IBAction)goFullScreen:(id)sender {

[UIView animateWithDuration:0.25
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     if (topSpaceConstraints.priority == 999) {
                         videoContainerSizeRatioConstraints.priority = 250;
                         [[UIApplication sharedApplication] setStatusBarHidden:YES];
                         [self.navigationController setNavigationBarHidden:YES];
                         topSpaceConstraints.priority = 250;
                     } else {
                         videoContainerSizeRatioConstraints.priority = 999;
                         [[UIApplication sharedApplication] setStatusBarHidden:NO];
                         [self.navigationController setNavigationBarHidden:NO];
                         topSpaceConstraints.priority = 999;
                     }
                     [self.view layoutIfNeeded];

                 }
                 completion:nil];

}

Solution

  • You have two options (maybe more): You create a view that is higher in the view hierarchy than your navigation controller view therefore you can just put something that is 'above'. Probably this would be the most visually appealing one and I'm sure most professional apps use this.

    The other option you have is just to hide the navigationbar when someone pushes the fullscreen button.

    UPDATE:

    Maybe a 'better' way for options 1:

    I looked at prev. project of mine and maybe you want to use this:

    Create a new window to contain your avplayer.

    Subclass UIView and implemnt a 'show' method like this:

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.alpha = 0;
    self.window.windowLevel = UIWindowLevelAlert;
    self.window.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.0f];
    
    [self.window addSubview:self];
    
    [self.window addSubview:self];
    [self.window makeKeyAndVisible];
    
    [UIView animateKeyframesWithDuration:0.3 delay:0 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{
    
            [UIView addKeyframeWithRelativeStartTime:0. relativeDuration:0.7 animations:^{
                // PROBABLY MORE ANIMATION HERE...
                self.alpha = 1;
            }];
    
            [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1 animations:^{
                self.window.backgroundColor = [UIColor colorWithWhite:0.0f alpha:self.targetDimmDensity];
    
            }];
        } completion:^(BOOL finished) {
    
        }];
    

    The self.window is a new @property (nonatomic, strong) UIWindow *window; I created!