首页 > 解决方案 > 有没有办法在 SwiftUI 中的动画之后执行函数?

问题描述

在 UIKit 中你可以这样做:

UIView.animate(withDuration: TimeInterval, animations: {
    //animation
  }) { (Bool) in
    //code which will be executed after the animation
}

SwiftUI 中是否有类似的东西,或者你能想出一个替代品吗?

标签: iosswiftswiftuiswift5xcode11

解决方案


这里描述了一种方法:

https://www.avanderlee.com/swiftui/withanimation-completion-callback/

该方法需要使用AnimatableModifier协议的自定义实现。实现起来并非完全微不足道,但它似乎确实解决了问题。


推荐阅读