【问题标题】:swift change view after animation动画后快速更改视图
【发布时间】:2020-12-16 17:10:27
【问题描述】:

我有一个带有 .ontapgesture 的动画,效果很好。到目前为止,一切都很好。 但我想在动画完成后调用我的下一个视图。但我不知道怎么做。是否可以选择在动画运行时构建延迟?

var body: some View {
Text("test")
    .scaleEffect(x: isButtonPressed ? 1.5 : 1, y: isButtonPressed ? 1.5 : 1)
   
    .animation(Animation.linear.repeatCount(5))
    .onTapGesture {
        isButtonPressed.toggle()
        jumpToNextView.toggle()

}
}

【问题讨论】:

标签: swift animation swiftui


【解决方案1】:

动画结束后可以使用DispatchQueue来执行jumpToNextView的切换。

Text("test")
    .scaleEffect(x: isButtonPressed ? 1.5 : 1, y: isButtonPressed ? 1.5 : 1)
    .animation(Animation.linear(duration: 0.25).repeatCount(5))
    .onTapGesture {
        isButtonPressed.toggle()
        //<< executed after 0.25 (duration) * 5 (repeat count)
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.25) {
            jumpToNextView.toggle()
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-14
    • 2019-01-26
    • 2021-08-13
    • 1970-01-01
    • 2021-05-03
    • 2014-10-31
    相关资源
    最近更新 更多