仅限子视图的iPhone电影轮播

时间:2011-06-24 14:23:02

标签: iphone objective-c xcode rotation mpmovieplayercontroller

我正在制作一个不允许旋转的应用,除非正在播放电影。我让应用程序旋转得很好,但是当我尝试观看电影时会出现问题。

模拟器被迫旋转,但电影没有。下面是一个例子:

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];,但编译器给了我一个错误,没有任何反应

1 个答案:

答案 0 :(得分:0)

您使用的是MPMoviePlayerController吗?

试试MPMoviePlayerViewController。该类是一个UIViewController,应该自行处理它的旋转。

只需调用方法[moviePlayerViewController moviePlayer];即可从视图控制器获取MPMoviePlayerController