static bool g_bIsPortrait = false;
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
if (g_bIsPortrait == false) {
//橫屏
return UIInterfaceOrientationMaskLandscape;
}else{
//豎屏
return UIInterfaceOrientationMaskPortrait;
}
}
+(void)setOrientation:(NSString *)isPortrait{
bool bIsPortrait=nullptr;
if([isPortrait isEqualToString:@"true"])
bIsPortrait=true;
else
bIsPortrait=false;
if(g_bIsPortrait == bIsPortrait){
return ;
}
g_bIsPortrait = bIsPortrait;
UIInterfaceOrientation interfaceOrientation = UIInterfaceOrientationUnknown;
if(bIsPortrait){
interfaceOrientation =UIInterfaceOrientationPortrait;
}
else{
interfaceOrientation =UIInterfaceOrientationLandscapeRight;
}
NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:interfaceOrientation];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
}