ios - 如何仅旋转子类 mpmovieplayer Controller 并将其他 View 固定为纵向

标签 ios objective-c orientation mpmovieplayercontroller

我正在使用 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/

相关文章:

ios - UIActivityViewController 通过 SMS 共享不接受 NSAttributedString

ios - Swift 中的 Objective-C AppAuth OIDAuthorizationService 类,以及 Objective-C -> Swift 翻译

android - 有时调用initLoader后没有得到onCreateLoader回调

ios - NSURLConnectionDataDelegate 函数顺序

ios - 在后台播放音频并使用静音开关静音

iphone - 当方向改变时, View 中何时重新加载资源?

ios - Unity VR LandscapeLeft 在 iOS 中不起作用

ios - UIButtons 在旋转到横向然后回到纵向后停止工作

ios - 将 Objective-C 桥接到 Swift 项目

ios - 适用于 IOS 的 vimeo iframe 如何从 UIWebView 的右侧隐藏 "like"和 "share"按钮