1

在 iOS 中,呈现 amodalViewController非常简单:

[self presentModalViewController:controller animated:YES];

或者:

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:controller animated:YES];

在 a modalViewController(如navigationController)内,您可以modalViewController再次呈现 a。有没有办法检测正在呈现多少个模态视图控制器?否则也许挂钩 presentModalViewController:animated:anddismissModalViewControllerAnimated:会是个好主意?谢谢!

4

2 回答 2

2

检查这个问题:

是否可以确定 ViewController 是否显示为 Modal?

您可以使用该代码“爬升”您的视图,直到找到不是模态视图控制器的视图。像:

while (isModal)
{
    currentViewController = currentViewController.presentingViewController;

    ...
}
于 2012-12-19T08:27:14.510 回答
0

我想我找到了一种方法来找到最顶层的 viewController,这应该有助于解决这个问题:

+ (UIViewController*)getTopMostViewController {
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    UIViewController *appRootViewController = window.rootViewController;
    UIViewController *topViewController = appRootViewController;
    while (topViewController.modalViewController != nil) {
        topViewController = topViewController.modalViewController;
    }
    return topViewController;

}

于 2013-10-16T02:11:53.777 回答