我想要在 onAppear 上为文本信息和 SF 符号添加一个 escapeIn/moveUp 动画。此后,我只希望 SF 符号永远按比例放大和缩小。目前,我已经设法永远缩小规模,但是当我设法链接时,easeIn/moveUp 动画也会永远重复自身,只应在出现时重复一次。
我在下面添加了一段图钉动画代码片段:
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 - 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
}
关于ios - 具有 EasyIn 动画,然后按顺序缩放动画,因为缩放动画会永远重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63535860/