xcode 如何让我的 MPMoviePlayerController 在横向播放?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12545626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make my MPMoviePlayerController Play in Landscape?
提问by jakife
I am trying to make my video from youtube play in landscape mode. I turned off landscape left and right for supported device orientation because if it was on, every view is able to go landscape. I'm building this for iOS 6. How do I make my video play in landscape.
我正在尝试以横向模式从 youtube 播放我的视频。我为支持的设备方向关闭了左右横向,因为如果它打开,每个视图都可以横向显示。我正在为 iOS 6 构建这个。如何让我的视频在横向播放。
Here is my code
这是我的代码
#import "VideoTViewController.h"
#import "HCYoutubeParser.h"
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTViewController ()
@end
@implementation VideoTViewController
@synthesize tLabel;
-(IBAction)playVideo
{
NSDictionary *videos = [HCYoutubeParser h264videosWithYoutubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=zz_bJ58LfCg&feature=youtu.be"]];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:[videos objectForKey:@"medium"]]];
[self presentViewController:mp animated:YES completion:nil];
}
Edit:
编辑:
I did the following:
我做了以下事情:
Made a new class
做了一个新班级
AboutNavViewController (which subclasses a UiNavigationController)
AboutNavViewController(它是 UiNavigationController 的子类)
#import "AboutNavViewController.h"
@interface AboutNavViewController ()
@end
@implementation AboutNavViewController
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@end
And in my aboutviewcontroller (which subclasses a uiviewcontroller)
在我的 aboutviewcontroller(它是 uiviewcontroller 的子类)中
#import "AboutViewController.h"
#import "AboutNavViewController.h"
@interface AboutViewController ()
@end
@implementation AboutViewController
@synthesize aLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame = CGRectMake(0, 0, 320, 44);
aLabel = [[UILabel alloc] initWithFrame:frame];
aLabel.backgroundColor = [UIColor clearColor];
[aLabel setFont:[UIFont fontWithName:@"SerifGothic LT Black" size:25]];
aLabel.text = @"Sephardi Jews";
aLabel.textAlignment = NSTextAlignmentCenter;
aLabel.textColor =[UIColor whiteColor];
self.navigationItem.titleView = aLabel;
AboutNavViewController *about = [[AboutNavViewController alloc] init];
[self presentViewController:about animated:YES completion:nil];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
@end
I get the following error:
我收到以下错误:
Unbalanced calls to begin/end appearance transitions for .
对 的开始/结束外观转换的不平衡调用。
What am I doing wrong?
我究竟做错了什么?
回答by rocky
Note: You must add landscape left and right to your supported interface orientations in Info.plist for this to work.
注意:您必须在 Info.plist 中向支持的界面方向添加左右横向,才能使其正常工作。
The system determines whether an orientation is supported by intersecting the value returned by the app's supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller.
系统通过将应用程序的 supportedInterfaceOrientationsForWindow: 方法返回的值与最顶层全屏控制器的 supportedInterfaceOrientations 方法返回的值相交来确定是否支持某个方向。
Added iOS 6 autorotation methods from previous answer"
从以前的答案中添加了 iOS 6 自动旋转方法”
@interface MyMovieViewController : MPMoviePlayerViewController
@end
@implementation MyMovieViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
@end