改變方向后,我需要在相同的相對位置上作業旋轉影片和矩形。現在,在更改設備方向后,矩形開始在螢屏上隨機飛行。
import SwiftUI
struct ContentView: View {
@State private var isAnimating = false
var animation: Animation {
Animation.linear(duration: 1)
.repeatForever(autoreverses: false)
}
var body: some View {
HStack {
Text("Hello, world!")
.padding()
Spacer()
Rectangle()
.frame(width: 20, height: 20)
.foregroundColor(.red)
.rotationEffect(Angle.degrees(isAnimating ? 360 : 0))
.animation(animation)
.onAppear {
isAnimating = true
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
uj5u.com熱心網友回復:
你只需要加入具有價值的影片,比如
Rectangle()
.frame(width: 20, height: 20)
.foregroundColor(.red)
.rotationEffect(Angle.degrees(isAnimating ? 360 : 0))
.animation(animation, value: isAnimating) // << here !!
.onAppear {
isAnimating = true
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/349773.html
標籤:ios 迅速 迅捷 swiftui-动画
