gpt4 book ai didi

iPhone 无法使用 MPMoviePlayerController 将视频旋转到横向模式

转载 作者:行者123 更新时间:2023-11-28 21:39:41 25 4
gpt4 key购买 nike

[更新]

按照建议,我更改了所有父 View Controller 以支持所有方向。我的应用程序结构如下:AppDelegate > RootViewController > Videos > VideoDetails > MPMoviePlayerViewController。

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

谢谢

[/更新]

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

- (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 转为横屏模式时,视频仍然以竖屏模式而非横屏模式播放 :( 应用程序中的所有 View Controller 仅支持竖屏方向。

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

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

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

- (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 上不再运行。我希望将来有时间研究这个问题:( [/EDIT]

好的,我修好了。这一切都与我对 iOS 如何通知应用程序方向更改的误解有关。我认为它会广播任何方向变化,但事实并非如此,它遵循您的 View 层次结构,并且由您来告诉任何 subview Controller 方向变化。这是我的毁灭。

我的应用包含以下设置:

窗口 > RootViewController > 标签栏 Controller > 导航 Controller > View Controller > MPMoviePlayerViewController

我将标签栏 Controller 子类化为仅在纵向模式下返回 true。我从 Root View Controller shouldAutoRotateToOrientation 方法返回了这个。这确保了所有 View 都是纵向的。

然后我使用从 RootViewController 调用的 presentMoviePlayerViewControllerAnimated 方法以模态方式呈现电影。这会自动调用自定义 MPMoviePlayerViewController 的 shouldAutoRotateToOrientation 方法,横向和纵向设置为 YES :)

关于iPhone 无法使用 MPMoviePlayerController 将视频旋转到横向模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8982111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com