項(xiàng)目中開(kāi)啟橫豎屏
- 自定義一個(gè) UINavigationController 鸥诽,并實(shí)現(xiàn)以上幾個(gè)方法
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
UIViewController *vc = self.topViewController;
if([vc isKindOfClass:[RemoteController class]]){//要橫屏的界面
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
UIViewController *vc = self.topViewController;
if([vc isKindOfClass:[RemoteController class]]){//要橫屏的界面
return YES;
}
//橫屏的上一個(gè)界面撑帖,要返回為YES,否則橫屏返回的時(shí)候上一界面不能還原成豎屏
if([vc isKindOfClass:[ConnectHome class]]){
return YES;
}
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController *vc = self.topViewController;
if([vc isKindOfClass:[RemoteController class]]){//要橫屏的界面
return UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;
}
//進(jìn)入界面時(shí)強(qiáng)制橫屏
- (void)viewWillAppear:(BOOL)animated
{
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];
}
}
//退出界面時(shí)強(qiáng)制豎屏
- (void)viewWillDisappear:(BOOL)animated
{
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];
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者