【发布时间】:2020-02-22 17:51:08
【问题描述】:
我有一个正在创建心跳模式的动画。问题是,一旦文本(在同一个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()
}
}
【问题讨论】: