2011-06-24 103 views
2

我正在研究一个应用程序,禁止旋转,除非电影正在播放。我的应用旋转得很好,但是当我尝试观看电影时出现问题。iPhone电影旋转只为子视图

模拟器被迫旋转,但电影没有。这方面的例子是以下:

Movie Player Error

我无法弄清楚如何过旋转的电影。我正在寻找只旋转子视图。我的代码如下:

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:finalURL]]; 
if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { 
       // Use the 3.2 style API 
       moviePlayer.controlStyle = MPMovieControlStyleDefault; 
       moviePlayer.shouldAutoplay = YES; 
       [self.view addSubview:moviePlayer.view]; 
       [moviePlayer setFullscreen:YES animated:YES]; 
      [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO]; 

      // Rotate the view for landscape playback 
      [[moviePlayer view] setBounds:CGRectMake(0, 0, 480, 320)]; 
      [[moviePlayer view] setCenter:CGPointMake(160, 240)]; 
      [[moviePlayer view] setTransform:CGAffineTransformMakeRotation(M_PI/2)]; 

      // Set frame of movieplayer 
      [[moviePlayer view] setFrame:CGRectMake(0, 0, 480, 320)]; 

      } else { 
       // Use the 2.0 style API 
       moviePlayer.movieControlMode = MPMovieControlModeHidden; 
       [moviePlayer play]; 
      } 
} 

编辑:我试过[moviePlayer setOrientation UIInterfaceOrientationLandscapeRight];但编译器给我一个错误和

+0

你一个真实的设备上测试的方法得到的视图控制器的MPMoviePlayerController? – Dancreek

+0

是的,它做同样的事情。 –

回答

0

是否使用了MPMoviePlayerController没有任何反应?

尝试MPMoviePlayerViewController。该类是一个UIViewController,并且应该处理它自身的旋转。

您可以通过只调用[moviePlayerViewController moviePlayer];

+0

我是,我只是忘了把它添加到问题。它现在在那里。 –