Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

横屏下使用 prefersStatusBarHidden 导致tabbar高度变成32 #376

Closed
ChenYilong opened this issue May 28, 2019 · 0 comments
Closed

Comments

@ChenYilong
Copy link
Owner

enter image description here



Base Info for this issue

  1. Version:Latest Version as here
  2. Language of App :Objective-C/Swift
  3. iOS System Version:iOS12
  4. Prototype(是否是真机):YES
  5. Issue Type:Crash、Bug、Enhancement(希望能支持一个新需求)、Q-A

1. How to reproduce the problem.

2. Please help me in this way.

3. Here is a Demo.

4. Here is my Debug log

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmethod-signatures"
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
   if (self.isForceLandscape) {
       //只支持横屏
       return UIInterfaceOrientationMaskLandscape;
   } else {
       //支持竖屏
       return UIInterfaceOrientationMaskPortrait;
   }
}
#pragma clang diagnostic pop


+ (AppDelegate *)sharedAppDelegate {
   return (AppDelegate *)[UIApplication sharedApplication].delegate;
}

- (void)yh_changeOrientationPortrait {
   AppDelegate *appdelegate= [AppDelegate sharedAppDelegate];
   appdelegate.isForceLandscape = NO;
   [appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:UIApplication.sharedApplication.keyWindow];
   if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
       NSNumber *num = [[NSNumber alloc]initWithInt:UIInterfaceOrientationPortrait];
       [[UIDevice currentDevice] performSelector:@selector(setOrientation:)withObject:(id)num];
       [UIViewController attemptRotationToDeviceOrientation];//这行代码是关键
       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];
   }
}

- (void)yh_changeOrientationLandscapeRight {
   AppDelegate *appdelegate= [AppDelegate sharedAppDelegate];
   appdelegate.isForceLandscape = YES;
   [appdelegate application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:UIApplication.sharedApplication.keyWindow];
   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];
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant