【问题标题】:Force MPMoviePlayerController to play in landscape强制 MPMoviePlayerController 横向播放
【发布时间】:2014-11-29 01:25:45
【问题描述】:

我是 iPhone 开发的新手,正在编写我的第一个应用程序。整个App只需要人像模式,除了播放电影。我正在使用 MPMoviePlayerController 启动电影,它以纵向模式播放。如何强制 MPMoviePlayerController 以横向播放所有电影。 我正在使用 Xcode 4 并为 iOS 4.0+ 构建。我是否需要在 info.plist 中输入一些设置以允许 MPMoviePlayerController 横向播放?

这是我用来初始化 MPMoviePlayerController 的代码:

MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL: url]; 
[self.view addSubview:theMovie.view];
theMovie.allowsAirPlay=YES;
[theMovie setFullscreen:YES animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play]; 

【问题讨论】:

    标签: iphone cocoa-touch ios


    【解决方案1】:

    将播放器嵌入到它自己的视图控制器中并实现shouldAutorotateToInterfaceOrientation,如下所示:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
    }
    

    【讨论】:

    • 这对我不起作用 - 我有一个显示电影的视图控制器,它完全处于横向模式,但电影仍然以纵向模式启动......想法?
    【解决方案2】:

    创建MPMoviePlayerViewController的子类:

    @interface MyMoviePlayerViewController ()

    @end

    @implementation MyMoviePlayerViewController
    
    - (BOOL)shouldAutorotate { return NO; }
    - (NSUInteger)supportedInterfaceOrientations {
      return UIInterfaceOrientationMaskLandscape;
    }
    
    @end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      相关资源
      最近更新 更多