12

我正在尝试收听presentedViewController 的更改,但看起来该属性不符合KVO(或者至少我无法从中获取更改)。UIViewController 中是否有办法在 UIViewController 主动呈现时监听更改?

4

1 回答 1

4

presentedViewController似乎不符合 KVO 标准,但可以通过覆盖以下相关呈现/解除方法来通知更改UIViewController

override func presentViewController(viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)?) {
    // will present view controller
    super.presentViewController(viewControllerToPresent, animated: flag, completion: completion)
}

override func dismissViewControllerAnimated(flag: Bool, completion: (() -> Void)?) {
    super.dismissViewControllerAnimated(flag, completion: completion)
    // did dismiss view controller
}

斯威夫特 4:

override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
...
}
于 2016-06-06T18:34:33.923 回答