开发者

MPMoviePlayerController re-orientation portrait to landscape and back to portrait (iOS 4.1)

开发者 https://www.devze.com 2023-01-20 19:51 出处:网络
Since iOS 3.2 the MPMoviePlayerController class allows to embed a movie in the view hierarchy. Now I\'m facing this issue: I create my portrait view by placing an instance of MPMoviePlayerController.

Since iOS 3.2 the MPMoviePlayerController class allows to embed a movie in the view hierarchy. Now I'm facing this issue: I create my portrait view by placing an instance of MPMoviePlayerController. When the user touch the "fullscreen" button this view enters in fullscreen mode but the view remains in portrait. When the user rotates the device the fullscreen movie view is not auto-rotated as my app forbids landscape interface orientation. So in order to allow auto-rotation of movie player fullscreen view, I changed my view controller shouldAutorotateToInterfaceOrientation: method to return YES for landscape if - and only if - the movie player is in full screen mode. This works perfectly: when the user enters in full screen and then rotates to landscape the player is auto-rotated to landscape and fills the entire screen.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    if(UIInterfaceOrientationIsP开发者_Go百科ortrait(interfaceOrientation)) {
        return(YES);
    }

    if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        return([movieController isFullscreen]);
    }

return(NO);
}

Now the issue arises when I touch the "Done" button in the full screen view while remaining in landscape. The full screen closes and then what I see is my original view autorotated: but I don't want this auto-rotation.

A partial, but not acceptable solution, is to listen for "MPMoviePlayerDidExitFullscreenNotification" and, if the interface is rotated to landscape, force re-orientation to using the undocumented and private function:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait]

This works but is not acceptable as usage of this method is forbidden.

I tried to force orientation using [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait] but as I'm in a Tab Bar this doesn't work (the UITabBar remains Landscape-sized).

Thanks for your help


You can use a separate view controller for MPMovieplayer. You don't have to override the

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

in the original view controller.

if you are using MPMoviePlayerViewController, everything is already set nicely for you, as the method shouldAutorotateToInterfaceOrientation: will return YES by default. You can use it as a subview or present it modally by calling
presentMoviePlayerViewControllerAnimated:


Check this out: MPMoviewPlayerController fullscreen playback rotation with underlying UIViewController with portrait mode only (rotation disallowed)

Maybe a little different problem, but solution may be the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号