【问题标题】:Alert with actionSheet style being shown with delayed title and message显示带有延迟标题和消息的 actionSheet 样式的警报
【发布时间】:2019-12-29 05:04:50
【问题描述】:

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

这些是 Apple 的 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)
    }

这就是它的样子:

任何帮助将不胜感激!提前致谢。

【问题讨论】:

  • 您提供的发行说明链接适用于 SwiftUI 应用程序。
  • 您从哪里拨打showRemoveConfirmationAlert
  • @MidhunMP 单击左侧的 NavigationBarButton 时,会显示一个带有 2 个按钮的警报,即删除设备和取消。单击删除设备会调用showRemoveConfirmationAlert。第一个警报仅包含 2 个操作按钮,因此不存在动画问题。

标签: ios swift ios13 uialertcontroller presentviewcontroller


【解决方案1】:

这是从 iOS 13 开始的默认行为。如果你想立即渲染,把动画改成 false

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

【讨论】:

  • 这也删除了警报本身的呈现动画,使其突然显示......也许唯一要做的就是祈祷他们尽快改回来?
【解决方案2】:

试试这个:

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)
    }
}

【讨论】:

  • 不幸的是,没有更好的结果:(还是谢谢!
【解决方案3】:

首先,感谢您的回答!

解决方案

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

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

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

它并没有改善按钮渲染,但我忘了删除它。


调查

我发现问题的方法是创建一个全新的项目并开始添加包含问题的项目部分。

在添加所有库并重新创建一些屏幕和行为但没有成功后,我尝试比较项目设置,在 Info.plist 上显示了这个不同的属性。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    相关资源
    最近更新 更多