我正在尝试以横向模式播放来自youtube的视频。我左右关闭了横向以获得支持的设备方向,因为如果它已打开,则每个视图都可以进行横向显示。我正在为iOS 6构建此功能。如何在横向播放视频。
这是我的代码
#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];
}
修改
我做了以下事情:
制作新课程
AboutNavViewController(它是UiNavigationController的子类)
#import "AboutNavViewController.h"
@interface AboutNavViewController ()
@end
@implementation AboutNavViewController
- (BOOL)shouldAutorotate {
return NO;
}
- (BOOL)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
@end
在我的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
我收到以下错误:
对于开始/结束外观转换的不平衡调用。
我做错了什么?
答案 0 :(得分:10)
注意:您必须在Info.plist中向左侧和右侧添加支持的界面方向才能使其生效。
系统通过将应用程序的supportedInterfaceOrientationsForWindow:方法返回的值与最顶层全屏控制器的supportedInterfaceOrientations方法返回的值相交来确定是否支持方向。
从之前的回答“
添加了iOS 6自动旋转方法@interface MyMovieViewController : MPMoviePlayerViewController
@end
@implementation MyMovieViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
@end