标签:
1.如图可对整个项目设置的所支持的横竖屏
2.若一个项目中只有某些控制器可以横屏其他都为竖屏 步骤如下(以只有播放视频的控制器可以横屏 当全屏播放时自动横屏)
(1)只勾选第一个home键在下
(2)在Appdelegate.h中 添加属性 @property(nonatomic)BOOL allowRotation;
(3)Appdelegate.m中的添加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//添加通知 视频播放进入全屏 和 退出全屏
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
return YES;
}
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
self.allowRotation = YES;
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
self.allowRotation = NO;
}
//窗口支持的方向 由属性allowRotation决定 allowRotation的值(由外界控制如是否是全屏播放 )
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation) {
return UIInterfaceOrientationMaskLandscapeRight ;
}
return UIInterfaceOrientationMaskPortrait;
}
(4)在只有某些控制器中的.m文件中添加属性和通知
@property(nonatomic, strong) MPMoviePlayerController* videoController;
//监听当屏幕改变方向时
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(changeScreen)
name:UIDeviceOrientationDidChangeNotification
object:nil];
/**
* 根据设备的方向(横竖屏)来改变播放器视图的大小(旋转)
*/
- (void)changeScreen
{
if (UIDeviceOrientationLandscapeLeft==[[UIDevice currentDevice] orientation]){
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
[self.videoController.view setTransform:transform];
self.videoController.view.frame = self.rootLayout.bounds;
CGSize size = self.videoController.view.frame.size;
[self.rootLayout addSubview:self.videoController.view];
NSLog(@"123,height:%f,width%f",size.height,size.width);
}else if(UIDeviceOrientationLandscapeRight==[[UIDevice currentDevice] orientation]){
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI/2);
[self.videoController.view setTransform:transform];
self.videoController.view.frame = self.rootLayout.bounds;
CGSize size = self.rootLayout.bounds.size;
NSLog(@"456,height:%f,width%f",size.height,size.width);
[self.rootLayout addSubview:self.videoController.view];
}
else if (UIDeviceOrientationPortrait==[[UIDevice currentDevice] orientation]){
// self.videoController.view.frame = self.playerContainerView.bounds;
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI*2);
[self.videoController.view setTransform:transform];
NSLog(@"123,height:111l");
[self.videoController.view setFrame:CGRectMake (0, 0, self.view.width, 180)];
[self.playerContainerView addSubview:self.videoController.view];
}else{
NSLog(@"456,height:111l");
}
}
标签:
原文地址:http://www.cnblogs.com/junhuawang/p/4607249.html