【发布时间】:2020-03-29 18:30:53
【问题描述】:
我有一个应用程序,我在其中以模态方式显示菜单。然后,当用户选择一个菜单选项时,该菜单会自行关闭,并在完成后根据用户选择的按钮以模态方式呈现另一个视图。
这种方法以前可以完美运行,但是从 iOS 13 开始它的行为就很奇怪。基本上,在用户触摸屏幕之前,它不会呈现第二个视图,而且我终其一生都无法找出它为什么会这样。
这是我的代码(我在流停止的地方添加了日志):
- (void) dismissPopUpMenu:(UIButton *)sender {
[self dismissViewControllerAnimated:NO completion:^{
if ( (sender.tag == 13 ) {
[self openPopUpWindow:sender];
}
}];
}
- (void) openPopUpWindow:(UIButton *)sender {
interactionDisabledLayer.alpha = 1.0f;
PopUpViewController *popUpController = [[PopUpViewController alloc] initWithPopUp:sender.tag];
popUpController.delegate = self;
NSLog(@"We get to here without problems.");
[self presentViewController:popUpController animated:NO completion:^{
NSLog(@"It only enters here if we touch the screen.");
self->interactionDisabledLayer.alpha = 0.0f;
}];
}
更新:使用计时器帮助延迟代码,但我认为这是一种肮脏的黑客行为,并希望找到更好的解决方案。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self presentViewController:popUpController animated:NO completion:^{
self->interactionDisabledLayer.alpha = 0.0f;
}];
});
【问题讨论】:
-
我不太记得ObjC,但有时在代码执行期间主线程很忙(如显示转换)时会发生这种行为。希望对你有帮助
-
可能是,但是在完成块中调用函数,这应该解决线程问题。应该...
标签: ios objective-c uiviewcontroller ios13