我有一个新的自定义UIWindow来显示只支持的fullSrceen ViewControllerUIInterfaceOrientationMaskLandscapeLeft
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationLandscapeLeft;
}
点击一个按钮即可打开"设置窗口.hidden=NO">
- (void)show {
UIWindowScene *scence = [UIApplicationsharedApplication].connectedScenes.allObjects.firstObject;
self.window = [[CustomWindow alloc]initWithWindowScene:scence];
CustomViewController *vc = [[CustomViewController alloc]init];;
self.window.rootViewController = vc;
self.window.hidden = NO;
self.window.windowLevel = 2;
[self.window makeKeyAndVisible];
}
和一个按钮关闭"set window.hidden=YES",
- (void)close {
self.window.hidden = YES;
self.window = nil;
}
一切都很好,但当我打开窗口,回到背景,进入前景,关闭窗口时,navigationbar
不在位置。
纵向状态
横向状态
背景状态
导航栏位置错误
代码在这里
我已经修复了这个错误。在显示自定义窗口之前使用presentViewController作为临时vc。
- (IBAction)showApp:(id)sender {
UIViewController *vc = [[UIViewController alloc]init];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
self.tempVc = vc;
[self presentViewController:vc animated:NO completion:^{
[self.app show];
}];
}