gpt4 book ai didi

swift - 阻止 SwiftUI 动画水平移动

转载 作者:行者123 更新时间:2023-11-28 11:24:39 25 4
gpt4 key购买 nike

我有一个正在创建心跳模式的动画。问题在于,一旦文本(在相同的 HStack 中)发生合理的变化,动画就会水平振荡,因为它被文本插入了。我怎样才能阻止这种情况发生?有没有一种方法可以锚定图像,从而不会发生这种戏剧性的水平移动?

        HStack(alignment: .bottom){
Text("\(self.hr)") + Text("BPM")
Image(systemName: "heart.fill")
.padding(.init(top: 5, leading: 5, bottom: 10, trailing: 5))
.foregroundColor(self.outdatedHR ? Color.gray : Color.red)
.scaleEffect(self.heart ? 1.05: 0.95, anchor: .center)
.opacity(self.heart ? 1.0: 0.75)
.animation(Animation.easeInOut.repeatForever())
.onAppear{
self.heart.toggle()
}

}

enter image description here

最佳答案

给你一个完美的答案

 .animation( Animation.easeInOut.repeatForever(), value: self.heart)

这将保证 self.heart 更改后动画重新启动

关于swift - 阻止 SwiftUI 动画水平移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58574404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com