带有actionSheet样式的警报显示,并带有延迟的标题和消息

时间:2019-12-29 05:04:50

标签: ios swift ios13 uialertcontroller presentviewcontroller

从iOS 13开始,带有actionSheet样式的警报显示为“已延迟”标题和消息。

这些是苹果公司的release notes

我已经进行了很多研究,但找不到如何使其与iOS 13.1之前的版本相同的功能,在iOS 13.1上,标题和消息是在操作按钮的同时呈现的。

这是创建警报并显示警报的方法:

    private func showRemoveConfirmationAlert() {
        let alert = UIAlertController(
            title: "Remove device?".localized(), 
            message: "Are sure you want to remove this device from your account?\nMake sure to unpair your device before removing it. This action cannot be undone.".localized(), 
            preferredStyle: .actionSheet
        )

        alert.addAction(UIAlertAction(title: "Remove".localized(), style: .destructive, handler: { _ in
            AnalyticsHelper.logRemoveDeviceConfirmedTapped()
            self.viewModel?.removeFromAccount()
        }))
        alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { _ in
            AnalyticsHelper.logCancelTapped()
        }))

        if let popoverController = alert.popoverPresentationController {
            popoverController.sourceView = self.view
        }

        self.present(alert, animated: true)
    }

这是它的样子:

Alert being shown with delayed title and message

任何帮助将不胜感激!预先感谢。

3 个答案:

答案 0 :(得分:0)

这是iOS 13及更高版本的默认行为。如果要立即渲染,请将动画更改为false

self.present(alert, animated: false, completion : nil)

答案 1 :(得分:0)

尝试一下:

private func showRemoveConfirmationAlert() {

    DispatchQueue.main.async {
        let alert = UIAlertController(
            title: "Remove device?".localized(), 
            message: "Are sure you want to remove this device from your account?\nMake sure to unpair your device before removing it. This action cannot be undone.".localized(), 
            preferredStyle: .actionSheet
        )

        alert.addAction(UIAlertAction(title: "Remove".localized(), style: .destructive, handler: { _ in
            AnalyticsHelper.logRemoveDeviceConfirmedTapped()
            self.viewModel?.removeFromAccount()
        }))
        alert.addAction(UIAlertAction(title: "Cancel".localized(), style: .cancel, handler: { _ in
            AnalyticsHelper.logCancelTapped()
        }))

        if let popoverController = alert.popoverPresentationController {
            popoverController.sourceView = self.view
        }

        self.present(alert, animated: true)
    }
}

答案 2 :(得分:0)

首先,谢谢您的回答!

解决方案

经过大量调查和测试,我发现问题出在Renders with edge antialiasing Info.plist 属性中。

在开发自定义按钮时,我在Info.plist文件的末尾添加了以下几行,以检查它是否使按钮的显示效果更好。

    <key>UIViewEdgeAntialiasing</key>
    <true/>

它并没有改善按钮的呈现,但是我忘了删除它。


调查

我发现问题的方式是创建一个全新的项目,并开始向该问题添加项目的一部分。

添加完所有库并重新创建了一些屏幕和行为均未成功后,我尝试比较项目设置,其中显示了Info.plist上的此不同属性。

此外,我在搜索属性时发现了this related question。我可能以前没有看过它,因为它是从2013年开始的,我认为这与自2019年9月发布iOS 13以来的最新iOS更改有关,