objective-c - 如何让我的 MPMoviePlayerController 横向播放?

标签 objective-c xcode mpmovieplayercontroller ios6

我正在尝试让我的 YouTube 视频以横向模式播放。我为支持的设备方向关闭了左右横向,因为如果它打开,每个 View 都可以横向显示。我正在为 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

我收到以下错误:

开始/结束外观转换的调用不平衡。

我做错了什么?

最佳答案

注意:您必须在 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.

从之前的答案中添加了 iOS 6 自动旋转方法"

@interface MyMovieViewController : MPMoviePlayerViewController
@end

@implementation MyMovieViewController

- (BOOL)shouldAutorotate 
{
    return YES;
}

- (NSInteger)supportedInterfaceOrientations 
{
    return UIInterfaceOrientationMaskLandscape;
}

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

@end

关于objective-c - 如何让我的 MPMoviePlayerController 横向播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12545626/

相关文章:

ios SystemSound 不会响应音量按钮

iphone - 完整整数的两倍

ios - swift : When adding a new file the device is iPhone but I can not change it

iphone - 核心数据 : I want the pk in my fetched objects

iphone - UIButton TouchUpInside 不工作

ios - 当MPMediaItem assetURL为零时如何解决?

objective-c - iPhone 中的卷页过渡动画不会让工具栏保持不变

objective-c - 如何从后台线程更新 cocoa 应用程序中的UI控件

ios - 多个 NSManagedObjectContexts 问题

ios - 无法使用 MPMoviePlayerController 从视频中获取多个图像。操作系统状态 -12433