没有动画的UIAlertController的dismiss方法是否同步执行?
Does UIAlertController's dismiss method without animation execute synchronously?
如果我调用(在UIViewController
)
alert.dismiss(animated: false, completion: nil)
print("executed after dismiss?")
鉴于警报是先前呈现的 UIAlertController
,dismiss 方法是否同步执行?
我能做吗:
alert.dismiss(animated: false, completion: nil)
let newAlert = UIAlertController(...)
present(newAlert, animated: true, completion: nil)
无需担心演示时出现问题 newAlert
?
与大多数动画方法一样,当您关闭 UIAlertController
时,您只是在让球滚动。视图控制器被异步关闭和删除。为了测试这一点,我们可以使用这样的代码:
let alert = UIAlertController(title: "Oh No!", message: ":(", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
alert.dismiss(animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
如上所示,警报视图控制器不会立即作为呈现的视图控制器被删除。您仍然可以在关闭旧警报后立即显示新警报。但是,最佳做法是将第二个警报的代码放在第一个警报的完成处理程序中。在呈现的视图控制器上调用 viewDidDisappear
之后调用此完成处理程序。
如果我调用(在UIViewController
)
alert.dismiss(animated: false, completion: nil)
print("executed after dismiss?")
鉴于警报是先前呈现的 UIAlertController
,dismiss 方法是否同步执行?
我能做吗:
alert.dismiss(animated: false, completion: nil)
let newAlert = UIAlertController(...)
present(newAlert, animated: true, completion: nil)
无需担心演示时出现问题 newAlert
?
与大多数动画方法一样,当您关闭 UIAlertController
时,您只是在让球滚动。视图控制器被异步关闭和删除。为了测试这一点,我们可以使用这样的代码:
let alert = UIAlertController(title: "Oh No!", message: ":(", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
alert.dismiss(animated: true, completion: nil)
print(presentedViewController) // Optional(<UIAlertController: 0x7fefe901e670>)
如上所示,警报视图控制器不会立即作为呈现的视图控制器被删除。您仍然可以在关闭旧警报后立即显示新警报。但是,最佳做法是将第二个警报的代码放在第一个警报的完成处理程序中。在呈现的视图控制器上调用 viewDidDisappear
之后调用此完成处理程序。