我想要在 onAppear 上为文本信息和 SF 符号添加一个 escapeIn/moveUp 动画。此后,我只希望 SF 符号永远按比例放大和缩小。目前,我已经设法永远缩小规模,但是当我设法链接时,easeIn/moveUp 动画也会永远重复自身,只应在出现时重复一次。
This is how my app representation looks like:
我在下面添加了一段引脚动画代码片段:
HStack (spacing: 20) {
Image(systemName: "pin")
.foregroundColor(.red)
.font(.title2)
.padding(.trailing, 5)
.scaleEffect(animationAmount)
.onAppear {
let baseAnimation = Animation.easeInOut(duration: 1)
let repeated = baseAnimation.repeatForever(autoreverses: true)
return withAnimation(repeated) {
self.animationAmount = 1.5
}
}
VStack (alignment: .leading) {
Text("Pin favourites").fontWeight(.semibold)
Text("You can pin your favourite content on all devices")
.foregroundColor(.gray)
}
Spacer()
}//HStack 2
完整代码在以下页面:SwiftUI - 在工作表中有一个固定的不可滚动的继续按钮 https://stackoverflow.com/questions/63534510/swiftui-in-sheet-have-a-fixed-continue-button-that-is-not-scrollable
您可以使用值加入动画,如下所示
.scaleEffect(animationAmount)
.animation(Animation.easeInOut(duration: 1).repeatForever(autoreverses: true), value: animationAmount)
.onAppear {
self.animationAmount = 1.5
}
此外,由于现在动画和状态唯一连接,不会与其他动画/状态冲突,因此您可以将最后两个修改器移动到最顶部的容器(而不是重复它们三次)
例如这里:
}//VStack for 3 criterias
.padding([.leading, .trailing], 20)
.animation(Animation.easeInOut(duration: 1).repeatForever(autoreverses: true), value: animationAmount)
.onAppear {
self.animationAmount = 1.5
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)