嘿,
我的应用程序带有 Tabbar 导航,其他所有内容都处于不支持旋转的纵向模式。现在我必须播放这段视频,它必须是横向的。
我正在使用基本上工作正常的 MPMoviePlayerController,但尽管据说它会自动旋转到横向模式,但它仍处于纵向模式。
- (IBAction) openFourthInfo:(id)sender{
NSURL *url = [NSURL URLWithString:@"http://my-video.mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userPressedDone:)
name:MPMoviePlayerWillExitFullscreenNotification
object:player];
[self.view addSubview:player.view];
[mainView setHidden:YES]; //Need to hide another subview here
player.fullscreen = YES;
[player play];
}
我就是这样称呼播放器的。在 userPressedDone:
和 moviePlaybackComplete:
中,我基本上只是设置 mainView.setHidden = YES;
,移除观察者,移除并释放播放器。
没什么特别的。知道为什么玩家保持纵向吗? 我试过了
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
它为不断变化的状态栏设置动画,但 View 保持不变。通过添加
[[player view] setBounds:CGRectMake(20, 0, 480, 320)];
[[player view] setCenter:CGPointMake(160, 240)];
[[player view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
没有任何反应。将 player view
替换为 self view
,我只是让父 View 旋转,而不是播放器 View 。
问题出在哪里,我该如何解决?我已经尝试了 5 个小时左右 -.-
谢谢!
最佳答案
默认情况下,MPMoviePlayerController 不再在横向模式下工作,因此要使其在横向模式下工作,您需要对 View 应用转换。
UIView * playerView = [moviePlayerController view];
[playerView setFrame: CGRectMake(0, 0, 480, 320)];
CGAffineTransform landscapeTransform;
landscapeTransform = CGAffineTransformMakeRotation(90*M_PI/180.0f);
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);
[playerView setTransform: landscapeTransform];
此外,如果您想要常规的全屏控件,请使用以下示例。
moviePlayerController.fullscreen = TRUE;
moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
关于iphone - MPMoviePlayerController 不会自动将旋转更改为横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6203320/