【问题标题】:How to update UI after delay in swiftswift延迟后如何更新UI
【发布时间】:2018-02-15 22:34:27
【问题描述】:
 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) { animations() }

我对 UI 进行了更改(在主线程中),我需要将进一步的动画延迟一段时间,然后(同步)执行它们。上面的代码有效,但出现“在从主线程访问引擎后,此应用程序正在从后台线程修改自动布局引擎。这可能导致引擎损坏和奇怪的崩溃”错误。

感谢您的帮助!

【问题讨论】:

  • 你在animations()做什么?背景资料?
  • @fguchelaar 不,animations() 是一个 UI 更改块。

标签: ios animation swift3 autolayout swift4


【解决方案1】:

你可以这样延迟

 UIView.animate(withDuration: 0.8, delay: 0.5, options: [], animations: {
   /// animations here
}, completion: nil)

【讨论】:

  • 我尽量避免使用这个功能。有没有其他办法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 1970-01-01
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多