首页 > 解决方案 > SwiftUI 动画影响内部对象

问题描述

我有疑问..如果我有几个视图,里面有按钮等元素,并且在父视图上也有动画。我如何避免该动画影响内部对象。在我的情况下,所有按钮都会从父视图中捕获延迟。我尝试使用.сlipped,但我只对.shadow选项有帮助,对动画没有帮助;)

例子:

ViewA(editAction: {

}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(0.8))

ViewB(editAction: {

}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(0.95))

ViewC(editAction: {

}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.1))
                            
ViewD(verified: .constant(true), editAction: {
                                
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.25))
                            
ViewE(knowMoreAction: {
                                
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.4))

标签: animationswiftui

解决方案


将动画显式链接到依赖值,例如

ViewE(knowMoreAction: {
                                
}).opacity(isShow ? 1 : 0)
.animation(Animation.easeOut(duration: 0.6).delay(1.4), value: isShow)

推荐阅读