【发布时间】:2022-10-20 15:59:59
【问题描述】:
我正在编写我的第一个 SwiftUI 应用程序,我想在文本上创建一个动画(以慢慢显示和隐藏此文本)。这是我的代码:
import SwiftUI
struct TrendLabel: View {
let trendType: String
@State private var animationAmount = 0.0
var body: some View {
HStack {
if(trendType != "aucune"){
Label(trendType, systemImage: "arrow.down.right")
.foregroundColor(trendType == "hausse" ? .red : .green)
.opacity(2 - animationAmount)
.animation(
.easeOut(duration: 1).delay(1).repeatForever(autoreverses: true),
value: animationAmount
)
}
}
.onAppear {
animationAmount = 1.6
}
}
}
struct TrendLabel_Previews: PreviewProvider {
static var previews: some View {
TrendLabel(trendType: "hausse")
}
}
但它似乎不起作用,因为我的文本以最小不透明度值 (here is a screenshot of the result) 冻结。
有人知道如何解决这个问题吗?
【问题讨论】: