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

≯℡__Kan透↙ 提交于 2019-12-17 23:09:58

问题


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(UIInterfaceOrientationIsPortrait(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


回答1:


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:




回答2:


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.



来源:https://stackoverflow.com/questions/3960665/mpmovieplayercontroller-re-orientation-portrait-to-landscape-and-back-to-portrai

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!