是否可以确定ViewController是否呈现为Modal? [英] Is it possible to determine whether ViewController is presented as Modal?

查看:111
本文介绍了是否可以确定ViewController是否呈现为Modal?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

因为 modalViewController 在iOS 6中已被弃用,这里有一个适用于iOS 5+的版本,并且没有警告编译。



Objective-C :

   - (BOOL)isModal {
return self.presentingViewController.presentedViewController == self
|| (self.navigationController!= nil&& self.navigationController.presentingViewController.presentedViewController == self.navigationController)
|| [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]];
}

Swift:

  var isModal:Bool {
return self.presentingViewController?.presentedViewController == self
|| (self.navigationController!= nil&& self.navigationController?.presentingViewController?.presentedViewController == self.navigationController)
|| self.tabBarController?.presentingViewController是UITabBarController
}

p>

Is it possible to check inside ViewController class that it is presented as modal view controller?

解决方案

Since modalViewController has been deprecated in iOS 6, here's a version that works for iOS 5+ and that compiles without warnings.

Objective-C:

- (BOOL)isModal {
    return self.presentingViewController.presentedViewController == self
      || (self.navigationController != nil && self.navigationController.presentingViewController.presentedViewController == self.navigationController)
      || [self.tabBarController.presentingViewController isKindOfClass:[UITabBarController class]];
}

Swift:

var isModal: Bool {
    return self.presentingViewController?.presentedViewController == self
        || (self.navigationController != nil && self.navigationController?.presentingViewController?.presentedViewController == self.navigationController)
        || self.tabBarController?.presentingViewController is UITabBarController
}

Hat tip to Felipe's answer.

这篇关于是否可以确定ViewController是否呈现为Modal?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆