iOS: Movie player view doesn't rotate

前端 未结 3 1337
借酒劲吻你
借酒劲吻你 2020-12-10 21:14

I want to rotate my movie player view explicitly (not using Autorotation delegate). I wrote following code for that and also put comments in it. The parent

3条回答
  •  無奈伤痛
    2020-12-10 21:33

    You are using MPMoviePlayerController in fullscreen mode, hence the rotation/s applied to its view (and/or its superview) are not being effective.

    When using fullscreen mode, MPMoviePlayerController is actually using a different approach by adding its rendering layer directly to a UIWindow - that is, it does effectively not use its view property.

    For getting the current UIWindow when a movie is playing in fullscreen, you may use the following snippet;

    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    if (!window)
    {
        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    }
    

    Once you got that window, apply your rotation/s directly to it.

    This however will result in many possible issues that are hard to overcome (trust me, been there, got a collection of Tshirts). As an alternative way, I would strongly suggest you to use a fake-fullscreen mode.

    Instead of initializing the player like you did

    [moviePlayer setFullscreen:YES animated:YES];
    

    Why not simply initializing its view's frame size to the entire screen - or the bounds of its superview like this

    moviePlayer.view.frame = myParentViewController.view.bounds;
    

    Then, for getting the fullscreen interface, use the following control style:

    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    

    That way, your resulting playback will adhere to any transformation done on the superview and you will be free of side effects.

提交回复
热议问题