【发布时间】:2019-09-27 09:44:34
【问题描述】:
由于我使用的是 iOS 13,我的每个 UIAlertController 都会显示大约半秒,然后在任何用户操作之前立即消失。有什么想法吗?
当我从应用程序的不同部分使用 UIAlertController 时,我使用了一个扩展,它允许我从经典视图和 collectionView(单元格、标题等)中弹出。
public extension UIAlertController {
func show() {
let win = UIWindow(frame: UIScreen.main.bounds)
let vc = UIViewController()
vc.view.backgroundColor = .clear
vc.view.tintColor = Theme.mainAccentColor
win.rootViewController = vc
win.windowLevel = UIWindow.Level.alert + 1
win.makeKeyAndVisible()
vc.present(self, animated: true, completion: nil)
}
}
这里是这个扩展使用的一个例子:
fileprivate func showMissingAlert() {
let alert = UIAlertController(title: "blablabla", message: "blablablablabla blabla", preferredStyle: UIAlertController.Style.alert)
alert.show()
alert.view.tintColor = Theme.mainAccentColor
let cancelAction = UIAlertAction(title: "OK, blabla", style: .default, handler: {(alert: UIAlertAction!) in print("ok, leave")})
alert.addAction(cancelAction)
}
在我的代码中进一步:
showMissingAlert()
在 iOS 13 之前,每个 UIAlert 都运行良好......自从我搬到 iOS 13 甚至 iOS 13.1 之后,它变得一团糟...... :(
您知道是什么原因造成的吗?
以及如何防止将 UIAlert 用作潜意识消息:)?
【问题讨论】:
-
但是以这种方式制作第二个窗口总是错误的;现在框架已经赶上你了。
标签: swift uialertcontroller ios13