在做視頻的時候需要視頻所在的頁面可以橫屏,但是整個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];
}
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。