让MpMoviePlayerViewController播放时自动横屏

来源:互联网 发布:python游戏开发平台 编辑:程序博客网 时间:2024/05/19 05:05

网上有很多关于MpMoviePlayerViewController播放时自动横屏的教程,但试用了好些个也不行.总结过后得出以下方法:


首先,在AppDelegate.m文件中,加入:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {//UIInterfaceOrientationMaskLandscape  支持左右横屏//UIInterfaceOrientationMaskAll  支持四个方向旋转//UIInterfaceOrientationMaskAllButUpsideDown 支持除了UpsideDown以外的旋转return UIInterfaceOrientationMaskAllButUpsideDown;}

再写一个继承自MPMoviePlayerViewController的类:

////  MyMoviePlayViewController.h//  Medicine////  Created by Jz on 14-3-17.//  Copyright (c) 2014年 Jz. All rights reserved.////重写MpMoviePlayerController类 实现自动横屏#import <MediaPlayer/MediaPlayer.h>@interface MyMoviePlayViewController : MPMoviePlayerViewController@end
在MyMoviePlayViewController.m中:

MyMoviePlayerViewController.m- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{    return UIDeviceOrientationIsLandscape(interfaceOrientation);}- (BOOL)shouldAutorotate{    return YES;}- (NSUInteger)supportedInterfaceOrientations{    return UIInterfaceOrientationMaskLandscape;}- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window{    return UIInterfaceOrientationMaskAllButUpsideDown;}
最后:

#import "MyMoviewPlayViewController"..........MyMoviePlayViewController *playerVC = [[MyMoviePlayViewController alloc] initWithContentURL:XXXXXXX];[self presentMoviePlayerViewControllerAnimated: playerVC];

这样 在播放的时候,自动就会跳转为横屏.并且返回后跳回竖屏.













0 0