在 UIKit 中,您可以执行以下操作:
UIView.animate(withDuration: TimeInterval, animations: {
//animation
}) { (Bool) in
//code which will be executed after the animation
}
Run Code Online (Sandbox Code Playgroud)
SwiftUI 中有没有类似的东西,或者你能想到一个替代品吗?
不熟悉SwiftUI,并且不熟悉此新框架的事实。我想知道是否有人熟悉如何Path在SwiftUI中设置动画。
例如,给定一个视图,可以这样简单地说RingView:
struct RingView : View {
var body: some View {
GeometryReader { geometry in
Group {
// create outer ring path
Path { path in
path.addArc(center: center,
radius: outerRadius,
startAngle: Angle(degrees: 0),
endAngle: Angle(degrees: 360),
clockwise: true)
}
.stroke(Color.blue)
// create inner ring
Path { path in
path.addArc(center: center,
radius: outerRadius,
startAngle: Angle(degrees: 0),
endAngle: Angle(degrees: 180),
clockwise: true)
}
.stroke(Color.red)
.animation(.basic(duration: 2, curve: .linear))
}
}
.aspectRatio(1, contentMode: .fit)
}
}
Run Code Online (Sandbox Code Playgroud)
显示的内容是:
现在,我想知道如何对内圈进行动画处理,即蓝线内的红线。我想要做的动画将是一个简单的动画,其中路径从头开始出现并遍历到结束。 …