小编Cre*_*omy的帖子

自iOS 13起,每个UIAlertController都会在用户响应之前自动消失

由于我使用的是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)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是此扩展名用法的示例:

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)
    }
Run Code Online (Sandbox Code Playgroud)

进一步在我的代码中:

showMissingAlert()
Run Code Online (Sandbox Code Playgroud)

在iOS …

swift uialertcontroller ios13

7
推荐指数
1
解决办法
651
查看次数

标签 统计

ios13 ×1

swift ×1

uialertcontroller ×1