【发布时间】:2023-03-31 18:37:01
【问题描述】:
我想在我的应用启动时展示一个模态视图控制器(用于登录屏幕),以及在用户点击主页按钮然后重新启动应用后它再次变为活动状态时。
我首先尝试在根视图控制器的viewDidAppear: 方法中呈现模态视图。这在应用首次启动时效果很好,但在应用再次激活时不会调用此方法。
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self presentModalView];
}
- (void)presentModalView {
if(![AuthenticationService sharedInstance].isAuthenticated) {
_modalVC = [self.storyboard instantiateViewControllerWithIdentifier:self.modalViewControllerIdentifier];
_modalVC.delegate = self;
[self presentViewController:_modalVC animated:YES completion:nil];
}
}
接下来,我尝试在applicationDidBecomeActive: 方法中从我的应用委托调用它。
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
ModalPresentingUISplitViewController *splitViewController = (ModalPresentingUISplitViewController *)self.window.rootViewController;
[splitViewController presentModalView];
}
这在表面上似乎工作正常,但我在日志中收到 Unbalanced calls to begin/end appearance transitions for <ModalPresentingUISplitViewController: 0x7251590> 警告。我觉得我在 UISplitView 完成呈现之前以某种方式呈现模态视图,但我不知道如何解决这个问题。
当应用程序激活时,如何“自动”从根视图控制器呈现模态视图,并在“正确”时刻执行,以免使拆分视图控制器失衡?
【问题讨论】: