// 支持自动转屏
- (BOOL)shouldAutorotate{
return YES;
}
//支持哪些转屏方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
//当点击全屏时,强制转屏
-(void)fullClick:(UIButton *)full
{
full.selected = !full.selected;
if (full.selected) {
if([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationLandscapeRight;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
//self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
}else
{
if([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIDeviceOrientationPortrait;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
//self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
//这里写上当是正常屏幕时要做的操作
self.view.backgroundColor = [UIColorwhiteColor];
}else if (toInterfaceOrientation ==UIInterfaceOrientationLandscapeRight) {
//这里写上当是横屏时要做的操作
self.view.backgroundColor = [UIColorblackColor];
}
}