链接带动画延迟的SwiftUI-仅显示最后一个动画,除非对象是显示所有动画的中间动画
在中,似乎有人给出了一个可以与动画链接在一起的解决方案。这对我来说很有意义,所以我尝试了一下,几乎奏效了。当对象不运动时,仅显示最后一个动画。但是,如果我中断当前动画,所有动画都会平滑播放。是否有遗漏的步骤,或者我没有正确设置 这是我的测试代码链接带动画延迟的SwiftUI-仅显示最后一个动画,除非对象是显示所有动画的中间动画,swift,swiftui,swiftui-animation,Swift,Swiftui,Swiftui Animation,在中,似乎有人给出了一个可以与动画链接在一起的解决方案。这对我来说很有意义,所以我尝试了一下,几乎奏效了。当对象不运动时,仅显示最后一个动画。但是,如果我中断当前动画,所有动画都会平滑播放。是否有遗漏的步骤,或者我没有正确设置 这是我的测试代码 import SwiftUI struct AnimObject: View { @State var position = CGPoint( x: AnimObject.screenWidth, y:
import SwiftUI
struct AnimObject: View {
@State var position = CGPoint(
x: AnimObject.screenWidth,
y: AnimObject.screenHeight / 2)
var body: some View {
VStack {
Circle()
.frame(width: 20, height: 20, alignment: .center)
.position(position)
Button(action: {
withAnimation(Animation.linear(duration: 1.0).delay(0.0)) {
self.position.x = CGFloat(0)
}
withAnimation(Animation.linear(duration: 1.0).delay(1.0)) {
self.position.x = AnimObject.screenWidth / 2
}
withAnimation(Animation.linear(duration: 1.0).delay(2.0)) {
self.position.x = CGFloat(0)
}
withAnimation(Animation.linear(duration: 1.0).delay(3.0)) {
self.position.x = AnimObject.screenWidth
}
}) {
Text("Button")
} // Button
} // VStack
} // body
}
extension AnimObject {
static let screenWidth = UIScreen.main.bounds.size.width
static let screenHeight = UIScreen.main.bounds.size.height
static let screenSize = UIScreen.main.bounds.size
}
struct AnimObject_Previews: PreviewProvider {
static var previews: some View {
AnimObject()
}
}