iPhone无法使用MPMoviePlayerViewController将电影旋转到横向模式 [英] iPhone cannot rotate movie to landscape mode using MPMoviePlayerViewController

查看:132
本文介绍了iPhone无法使用MPMoviePlayerViewController将电影旋转到横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[update]

按照建议,我更改了所有父视图控制器以支持所有方向。我的app结构如下:AppDelegate> RootViewController> Videos> VideoDetails> MPMoviePlayerViewController。

As was recommended I changed all the parent view controllers to support all orientations. My app structure is as follows: AppDelegate > RootViewController > Videos > VideoDetails > MPMoviePlayerViewController.

如果我改变所有这些以支持所有方向,视频将以横向播放。但支持所有方向并不是我想要的,并导致其他问题。还有其他工作或我可以做的其他事情吗?

The video will play in landscape if I change all these to support all orientations. But supporting all orientations is not what I want and causes other issues. Is there any other work around or anything else I can do?

谢谢

[/ update]

[/update]

我有一个基于肖像的iPhone应用程序,它使用MPMoviePlayerViewController的自定义子类显示视频。当用户按下播放时,我创建了这个类的实例并按模式呈现它如下:

I have an portrait based iPhone app that displays videos using a custom subclass of MPMoviePlayerViewController. When the user presses play I create an instance of this class and present it modally as follows:

- (IBAction) playPressed:(id)sender {

NSString *filepath = [[NSBundle mainBundle] pathForResource:self.currentVideoModel.videoFileName ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];

// MovieViewController is just a simple subclass of MPMoviePlayerViewController
self.moviePlayerController = [[MovieViewController alloc] initWithContentURL:fileURL]; 

// full screen code.
[self.moviePlayerController.moviePlayer setScalingMode:MPMovieScalingModeFill];
[self.moviePlayerController.moviePlayer setFullscreen:TRUE];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayerController];

[self presentMoviePlayerViewControllerAnimated:self.moviePlayerController];
}

问题是它在肖像方面表现不错,但当我将iPhone转为视频仍然以纵向而不是横向播放:(应用程序中的所有视图控制器仅支持纵向方向。

The problem is that it plays fine in portrait but when I turn the iPhone to landscape the video still plays in portrait and not landscape :( All the view controllers in the app only support portrait orientation.

我的MPMoviePlayerViewController子类仅覆盖以下方法以允许方向更改但没有影响:

My MPMoviePlayerViewController subclass only overrides the following method to allow for orientation changes but it has no affect:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

我甚至尝试以编程方式旋转视频,但绝对没有运气,它始终处于纵向模式。

I've even tried to programmatically rotate the video but with absolutely no luck, it always stays in portrait mode.

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
    return true;
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI * 2)];
    return true;
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
    [self.view setTransform:CGAffineTransformIdentity];
    return true;
}
else return false;

}

推荐答案

以下解决方案在iOS5上完美运行,但不再适用于iOS6。我希望将来有时间来研究这个问题:([/编辑]

The below solution worked perfectly on iOS5 but no longer works on iOS6. I may get some time to look into this issue in the future hopefully :( [/EDIT]

好的我修好了。这与我的误解有关关于iOS如何通知应用程序的方向更改。我认为它会广播任何方向更改,但它没有,它遵循您的视图层次结构,由您来告诉任何子视图控制器方向更改。这是我的撤消。

OK I fixed it. It was all to do with my mis-understanding of how iOS notifies an app of orientation changes. I thought it broadcasts out any orientation change but it doesn't, it follows your view hierarchy and it is up to you to tell any child view controllers of an orientation change. This was my undoing.

我的应用包括以下设置:

My app consisted of the following set up:

窗口> RootViewController> tabbar controller> nav controller>视图控制器> MPMoviePlayerViewController

window > RootViewController > tabbar controller > nav controller > view controller > MPMoviePlayerViewController

我将tabbar控制器子类化为仅在纵向模式下返回true。我从根视图控制器返回此< shouldAutoRotateToOrientation 方法。这确保了所有视图都只是肖像。

I subclassed the tabbar controller to only return true for portrait mode. I returned this from the root view controllers shouldAutoRotateToOrientation method. This ensured that all views will be portrait only.

然后我使用 presentMoviePlayerViewControllerAnimated 从RootViewController调用的方法。这会自动调用自定义MPMoviePlayerViewController的 shouldAutoRotateToOrientation 方法,该方法对于横向和纵向都设置为YES:)

Then I presented the movie modally using the presentMoviePlayerViewControllerAnimated method called from the RootViewController. This automatically called the custom MPMoviePlayerViewController's shouldAutoRotateToOrientation method which was set to YES for both landscape and portrait :)

这篇关于iPhone无法使用MPMoviePlayerViewController将电影旋转到横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆