我正在使用 xcdYoutubeVideoViewController,它是 MPMoviePlayerController 的子类。我的申请是纵向的。要启动电影播放器,我这样做:
UINavigationController *navBarController = (UINavigationController*)[[[UIApplication sharedApplication] keyWindow] rootViewController] ;
[navBarController presentMoviePlayerViewControllerAnimated:vc];
其中 vc 是 XCDYouTubeVideoPlayerViewController 的实例。如何仅允许在此 View 中旋转并在电影播放器中按下完成按钮后将应用程序恢复为纵向?
最佳答案
您应该在每个 View Controller 中覆盖:-(BOOL) shouldAutorotate
。如果您希望该 View Controller 旋转 NO,则返回 YES。请务必检查 Storyboard设置中支持的方向。
更新:在呈现玩家的父 Controller 中试试这个:
- (BOOL)shouldAutorotate
{
// 1. check if the parent presentedViewController is the nav containing the player
// 2. if yes, return YES, NO otherwise
}
如果应用根 Controller 是一个导航 Controller ,继承 UINavigationViewController
并使用该类在 App Delegate 中创建应用 Root View Controller
@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];
}
关于ios - 如何仅旋转子类 mpmovieplayer Controller 并将其他 View 固定为纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25638064/