如何仅旋转子类化的mpmovieplayer控制器并使其他视图固定为人像 [英] How to rotate only the subclassed mpmovieplayer controller and keeping other views fixed to portrait
问题描述
我正在使用xcdYoutubeVideoViewController,它是MPMoviePlayerController的子类.我的申请是纵向的.要启动电影播放器,我正在这样做:
I am using xcdYoutubeVideoViewController which is subclassed from MPMoviePlayerController. My application is in portrait. To launch the movieplayer, I am doing this:
UINavigationController *navBarController = (UINavigationController*)[[[UIApplication sharedApplication] keyWindow] rootViewController] ;
[navBarController presentMoviePlayerViewControllerAnimated:vc];
其中vc是XCDYouTubeVideoPlayerViewController的实例.如何仅在此视图中允许旋转,并在Movieplayer中按完成"按钮将应用程序恢复为纵向?
where vc is instance of XCDYouTubeVideoPlayerViewController. How can I allow rotation only in this view and on pressing done button in movieplayer bring the application back to portrait?
推荐答案
您应该在每个视图控制器中覆盖:-(BOOL) shouldAutorotate
.如果您希望该视图控制器旋转NO,则返回YES.请确保在情节提要设置中检查支持的方向.
You should override: -(BOOL) shouldAutorotate
in each view controller. Return YES if you want that view controller to rotate NO otherwise. Be sure to check the supported orientation on your storyboard setting.
更新:在显示播放器的父控制器中,尝试以下操作:
Update: In your parent controller that presents the player try this:
- (BOOL)shouldAutorotate
{
// 1. check if the parent presentedViewController is the nav containing the player
// 2. if yes, return YES, NO otherwise
}
如果应用程序根控制器是导航控制器,请子类UINavigationViewController
并使用该类在App Delegate中创建应用程序根视图控制器
If the app root controller is a Navigation Controller, subclass UINavigationViewController
and use that class in creating the app root view controller in App Delegate
@implementation ANavigationViewControllerSubClass
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
这篇关于如何仅旋转子类化的mpmovieplayer控制器并使其他视图固定为人像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!