我的整个应用程序是在肖像模式,我在我的应用程序播放youtube视频。对于你来说,我用的是UIWebview。当用户单击UIWebview中的play按钮时,它会自动启动MPMoviePlayerController。因此,我没有声明任何MPMoviePlayerController对象。所以我希望MPMoviePlayerController同时支持人像和景观定位。所以请建议。
发布于 2014-10-08 13:26:02
如果使用NavigationController,则可以将其子类并执行以下操作:
#import "MainNavigationController.h"
#import <MediaPlayer/MediaPlayer.h>
@implementation MainNavigationController
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([[[self.viewControllers lastObject] presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
{
return UIInterfaceOrientationMaskAll;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
@end然后,你应该设置你的应用程序来支持所有的方向,只有当它在播放你的电影“MPMoviePlayerController`”时,这段代码才允许方向改变。
当调用您的movie时,您应该发送一个通知,因此如果用户在portrait以外的任何方向关闭它,它将切换回portrait。
就像这样:
- (IBAction)playButton:(id)sender {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackDidFinish)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.player.moviePlayer];
NSURL *url = [NSURL URLWithString:videoUrl];
self.player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[self presentMoviePlayerViewControllerAnimated:self.player];
}
-(void)moviePlaybackDidFinish
{
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}这应该是为了你,让我知道是怎么回事。
https://stackoverflow.com/questions/26257615
复制相似问题