[英]SwiftUI strange animation behaviour
我在頁面上有一個非常簡單的微調器動畫。
struct SmallSpinner: View {
@State private var spinXSmall = false
var body: some View {
Circle() // X-Small
.trim(from: 1 / 4, to: 1)
.stroke(style: StrokeStyle(lineWidth: 1, lineCap: .round, lineJoin: .round))
.foregroundColor(Color(#colorLiteral(red: 0.6588235294, green: 0.6588235294, blue: 0.6745098039, alpha: 1)))
.frame(width: 12, height: 12)
.rotationEffect(.degrees(spinXSmall ? 0 : 360))
.scaleEffect(spinXSmall ? 1 : 0.8)
.animation(Animation.easeOut(duration: 1).repeatForever(autoreverses: false))
.onAppear {
self.spinXSmall.toggle()
}
}
}
該問題是由於 NavigationView 中的一個問題而發生的,並且尚未解決,因此您需要做的是在 DispatchQueue 中添加 spinXSmall 的切換,並向動畫 Modifier 添加一個值並為其賦予 spinXSmall
struct SmallSpinner: View {
@State private var spinXSmall = false
var body: some View {
Circle() // X-Small
.trim(from: 1 / 4, to: 1)
.stroke(style: StrokeStyle(lineWidth: 1, lineCap: .round, lineJoin: .round))
.foregroundColor(Color(#colorLiteral(red: 0.6588235294, green: 0.6588235294, blue: 0.6745098039, alpha: 1)))
.frame(width: 12, height: 12)
.rotationEffect(.degrees(spinXSmall ? 0 : 360))
.scaleEffect(spinXSmall ? 1 : 0.8)
.animation(Animation.easeOut(duration: 1).repeatForever(autoreverses: false),value:spinXSmall)
.onAppear {
DispatchQueue.main.async {
self.spinXSmall.toggle()
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.