如何旋转MPMoviePlayerController [英] How To Rotate An MPMoviePlayerController

查看:87
本文介绍了如何旋转MPMoviePlayerController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个iPhone应用程序,可以根据需要从Web服务播放视频。

I am building an iPhone app that plays videos on demand from a web service.

视频在MPMoviePlayerController中播放,一切正常,在iPhone设备上。

The videos play in an MPMoviePlayerController, and everything works fine on the iPhone device.

然而,当一个人在iPad上加载iPhone应用程序时,视频会播放人像模式(顶部和底部带有信箱),而不是像他们那样在iPhone上。

However, when one loads up the iPhone application on an iPad, the videos play Portrait mode (with letterboxing on the top and bottom), instead of Landscape Left like they do on the iPhone.

首先,视频根本没有出现,但是我通过将MPMoviePlayerControllers视图添加到创建它的视图作为子视图来修复此问题,然后将其设置为全屏播放。

At first the videos were not appearing at all, however I fixed this by adding the MPMoviePlayerControllers view to the view that is creating it, as a subview, and then set it to play fullscreen.

-

编辑原文:

我现在可以在iPad上全力以赴地播放它。有没有办法阻止它旋转,只是让它玩LandscapeLeft?

I now have it playing on the iPad in all rotations. Is there any way to stop it rotating, and just have it play LandscapeLeft?

谢谢,
Dwaine

Thanks, Dwaine

推荐答案

iPad应用程序应支持所有四种界面方向。

iPad apps are supposed to support all four interface orientations.

编辑:我的避风港设法找到官方文件来引用。可能只是iPad应用程序应该能够在所有方向上启动,但是如果它合情合理,你可以强制使用某些位置。 Apple是否拒绝您的应用是另一个问题,但我认为他们不太可能拒绝播放视频的视频应用。

I haven't managed to find official docs to cite. It might be simply that iPad apps are supposed to be able to launch in all orientations, though you can force some bits to be landscape if it's "sensible". Whether Apple rejects your app or not is another issue, but I think they're unlikely to reject a video app that plays video in landscape.

经过一些实验,以下似乎工作:

After some experimentation, the following seems to work:

@interface MyMovieViewController : MPMoviePlayerViewController
@end

@implementation MyMovieViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

@end

然后只是实例化MyMovieViewController而不是MPMoviePlayerViewController。

Then just instantiate MyMovieViewController instead of MPMoviePlayerViewController.

编辑2: MPMoviePlayerViewController与MPMoviePlayerController不同;你用它来获得2.0-3.1 MPMoviePlayerController的行为。您需要将视图控制器添加到VC层次结构中,但它非常简单(并且比使用视图转换更容易):

EDIT 2: MPMoviePlayerViewController is not the same as MPMoviePlayerController; you use it to get the behaviour of the 2.0-3.1 MPMoviePlayerController. You need to add the view controller to the VC hierarchy, but it's pretty simple (and a lot easier than messing around with view transforms):

MPMoviePlayerViewController * vc = [[MyMovieViewController alloc] initWithContentURL:aUrl];
[self presentMoviePlayerViewControllerAnimated:vc];
[vc.moviePlayer play];

这篇关于如何旋转MPMoviePlayerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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