【问题标题】:Calling presentModalViewController just after dismissModalViewControllerAnimated has problems在dismissModalViewControllerAnimated之后调用presentModalViewController有问题
【发布时间】:2011-05-01 11:14:33
【问题描述】:

我有密码

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
    [menuViewController dismissModalViewControllerAnimated:YES];
    [GameKitWrapper getSingleton].match = match;
    match.delegate = [GameKitWrapper getSingleton].remotePlayer;
    [menuViewController presentModalViewController:avatarSelectionViewController
                                      animated:YES];
}

但我有一个问题,即解雇有效,但不是现在。当我将dismissModalViewControllerAnimated:YES 更改为dismissModalViewControllerAnimated:NO 时,它起作用了,但看起来不太好。

感谢任何帮助。

【问题讨论】:

    标签: iphone objective-c ios modalviewcontroller


    【解决方案1】:

    @adam 有正确的想法,但您不想等待一些任意延迟。这很脆弱,因为动画可能需要任何时间才能完成。您想等待前一个视图控制器真正完成关闭。根据我的经验,最好将其放在您当前视图控制器的viewDidAppear: 中。这将在您的模态完全消失后调用。有关解决类似问题的一些示例代码,请参阅 this question

    【讨论】:

    【解决方案2】:

    尝试等待一秒钟......

    - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
    {
        [menuViewController dismissModalViewControllerAnimated:YES];
        [GameKitWrapper getSingleton].match = match;
        match.delegate = [GameKitWrapper getSingleton].remotePlayer;
        [self performSelector:@selector(presentModal) withObject:nil afterDelay:1.0];
    }
    
    - (void)presentModal {   
        [menuViewController presentModalViewController:avatarSelectionViewController
                                              animated:YES];
    }
    

    【讨论】:

    • ya.. 在同一个 runloop 中解散和呈现 UIView 控制器可能会导致真正的 UI 问题,甚至崩溃(至少在我使用的以前的 SDK 中)。而且我经常发现,简单地延迟呈现下一个视图控制器并不能保证。因此,我完全避免了这种设计。
    • 等待一段时间是脆弱的。如果太长,应用程序将不必要地无响应;如果太短,您当前的通话将失败。我在这里找到了一个不依赖时间的解决方案:stackoverflow.com/a/8317603/126855
    【解决方案3】:

    尝试调用:

    [menuViewController dismissModalViewControllerAnimated:NO];
    

    打电话之前:

    [menuViewController presentModalViewController:avatarSelectionViewController
                        animated:YES];
    

    【讨论】:

    • -1 提问者已经尝试过了,并且反对缺少关闭视图控制器的动画并且不希望它消失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多