在做视频的时候需要视频所在的页面可以横屏,但是整个APP中其他页面都是不允许横屏的,这个时候要怎么做呢?
AppDelegate.h
@property (nonatomic, assign) BOOL allowRotation;
AppDelegate.m
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.allowRotation) {
return UIInterfaceOrientationMaskPortrait|
UIInterfaceOrientationMaskLandscapeLeft|
UIInterfaceOrientationMaskLandscapeRight;
} else {
return UIInterfaceOrientationMaskPortrait;
}
}
视频详情页:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
SET_UIStatusBarStyleLightContent;
[self.navigationController setNavigationBarHidden:YES animated:YES];
// 允许横屏操作
[(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (_needInputTime) {
[self inputPlayTime];
}
// 禁止横屏操作
[(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self];
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 = UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。