【问题标题】:How to rotate only the subclassed mpmovieplayer controller and keeping other views fixed to portrait如何仅旋转子类 mpmovieplayer 控制器并将其他视图固定为纵向
【发布时间】:2014-09-03 06:55:51
【问题描述】:

我正在使用从 MPMoviePlayerController 继承的 xcdYoutubeVideoViewController。我的申请是纵向的。要启动电影播放器​​,我这样做:

UINavigationController *navBarController = (UINavigationController*)[[[UIApplication sharedApplication] keyWindow] rootViewController] ;
[navBarController presentMoviePlayerViewControllerAnimated:vc];

其中 vc 是 XCDYouTubeVideoPlayerViewController 的实例。如何仅在此视图中允许旋转,并在电影播放器​​中按下完成按钮时将应用程序恢复为纵向?

【问题讨论】:

  • 是的,它是一个导航控制器。我这样做了: UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:btVC]; self.window.rootViewController = 导航控制器;其中 btVC 是 UIViewController 的子类

标签: ios objective-c orientation mpmovieplayercontroller


【解决方案1】:

您应该在每个视图控制器中覆盖:-(BOOL) shouldAutorotate。如果您希望视图控制器旋转 NO,则返回 YES。请务必检查情节提要设置中支持的方向。

更新:在呈现播放器的父控制器中尝试以下操作:

- (BOOL)shouldAutorotate
{
     // 1. check if the parent presentedViewController is the nav containing the player

     // 2. if yes, return YES, NO otherwise
}

如果应用根控制器是导航控制器,则子类化 UINavigationViewController 并使用该类在 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]; 
}

【讨论】:

  • 覆盖 shouldAutorotate 没有帮助。我需要在哪里使用preferredInterfaceOrientationForPresentation?它应该在父视图还是电影播放器​​中?
  • 问题:app的根控制器是什么,是UINavigationView控制器吗?
  • 是的,它是一个导航控制器。我这样做了: UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:btVC]; self.window.rootViewController = 导航控制器;其中 btVC 是 UIViewController 的子类
  • 我还在应用设置中添加了对所有方向的支持,这样它就不会阻止我的电影播放器​​旋转。但现在,一切都在旋转。
  • 嘿.. 这里的 topViewController 到底是什么
猜你喜欢
  • 2013-02-06
  • 2012-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 2016-09-02
相关资源
最近更新 更多