gpt4 book ai didi

ios - 重新定位 UIAlertView

转载 作者:搜寻专家 更新时间:2023-10-31 08:24:51 27 4
gpt4 key购买 nike

我想在打开 ViewController 时在屏幕底部简化一个 UIAlertView

现在,我创建一个警报 View ,在 2 秒后显示它并隐藏警报。
但是,警报 View 仅显示在屏幕中央。

如何将它重新定位到屏幕底部?

这是我的代码:

let alert = UIAlertController(title: "", message: "Please Swipe To Refresh After 2 seconds", preferredStyle: .alert)
alert.view.frame.origin.x = 150
alert.view.frame.origin.y = 250
self.present(alert, animated: true, completion: nil)
let indicator = UIActivityIndicatorView(frame: alert.view.bounds)
indicator.autoresizingMask = [.flexibleWidth, .flexibleHeight]
alert.view.addSubview(indicator)
indicator.isUserInteractionEnabled = false
indicator.startAnimating()
let when = DispatchTime.now() + 2
DispatchQueue.main.asyncAfter(deadline: when) {
alert.dismiss(animated: true, completion: nil)
}

最佳答案

您不能移动 UIAlertController 及其演示样式集,即使有解决方法也不要使用它。为了实现你想要的,你有不同的选择:

  • 使用一个简单的 UIView 子类,它只需要在 show 方法中使用您想要用作 super View 的 View
  • 创建一个 UIViewController 子类并使用 UIPresentationController 呈现它,如果您是 iOS 开发的新手,这可能会非常困难
  • 使用 github 上已有的库之一,例如 this

关于ios - 重新定位 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44800052/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com