iPhone 电影仅旋转子视图
我正在开发一个应用程序,除非正在播放电影,否则不允许旋转。我的应用程序旋转得很好,但当我尝试观看电影时出现了问题。
模拟器被迫旋转,但电影却没有。下面是一个示例:
我也不知道如何旋转影片。我只想旋转子视图。我的代码如下:
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];
但是编译器给了我一个错误并且没有任何反应
I am working on an app that disallows rotation unless a movie is playing. I have the app rotated just fine, but the issue comes about when I try to view the movie.
The simulator is forced to rotate, but the movie does not. An example of this is below:
I can't figure out how to rotate the movie too. I am looking to rotate only the subview. My code is below:
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];
}
}
EDIT: I tried [moviePlayer setOrientation UIInterfaceOrientationLandscapeRight];
but the complier gives me an error and nothing happens
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是
MPMoviePlayerController
吗?尝试使用
MPMoviePlayerViewController
。该类是一个 UIViewController,应该自行处理旋转。只需调用方法
[moviePlayerViewController moviePlayer]; 即可从视图控制器获取 MPMoviePlayerController;
Are you using the
MPMoviePlayerController
?Try the
MPMoviePlayerViewController
. That class is a UIViewController and should handle the rotation on it self.You get the MPMoviePlayerController from the view controller by just calling the method
[moviePlayerViewController moviePlayer];