【问题标题】:ViewController Only Presented after User Touches the ScreenViewController 仅在用户触摸屏幕后呈现
【发布时间】: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


【解决方案1】:

用计时器延迟呈现第二个 UIViewController 的代码似乎有帮助,但这是一个相当肮脏的 hack,我想找到一个更好的解决方法。如果有人有适当的解决方案,请将其作为答案发布,我会尽可能接受。

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;
        }];
    });

【讨论】:

    猜你喜欢
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多