【发布时间】:2021-08-31 16:34:34
【问题描述】:
这是一个简单的操作表,
let choice = UIAlertController(title: "Choose", message: nil, preferredStyle: .actionSheet)
choice.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in
self.happyCamera() }))
choice.addAction(UIAlertAction(title: "Album", style: .default, handler: { _ in
self.happyAlbum() }))
choice.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
somewhere?.present(choice, animated: false, completion: nil)
当动作表出现时(注意 present#animated 为假),它只是点击屏幕,没有俗气的动画。
但是,当用户点击三个选项中的一个,或者点击“关闭”时,操作表会通过使用俗气的动画离开屏幕。
(特别是在 10.3 中,它会从屏幕上向下滑动。)
有没有办法关闭退出动画?
如果你继承 UIAlertController...它不起作用?
正如 DS 建议的那样,您可以继承 UIAlertController。
然而——奇怪的是——它什么也没做。这是一个测试
func _test() {
let msg = SuperiorUIAlertController(
title: "Hello", message: "Hello",
preferredStyle: UIAlertControllerStyle.alert)
msg.addAction(UIAlertAction(
title: "OK", style: UIAlertActionStyle.default,
handler: nil))
let win = UIWindow(frame: UIScreen.main.bounds)
let vc = UIViewController()
vc.view.backgroundColor = .clear
win.rootViewController = vc
win.windowLevel = UIWindowLevelAlert + 1
win.makeKeyAndVisible()
vc.present(msg, animated: false, completion: nil)
}
class SuperiorUIAlertController: UIAlertController {
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
print("You should see this! \(flag)")
self.dismiss(animated: false, completion: completion)
}
}
确实,“你应该看到这个”的文字从未出现。
【问题讨论】:
-
在处理程序中添加dismiss
-
你被设置为 false 的动画为 Present 而不是 Dismiss。
-
@Fattie 查看我的更新答案
标签: ios uialertcontroller