【发布时间】:2020-10-20 13:32:40
【问题描述】:
我有以下情况:
我想用自定义动画翻转这个形状。不知道怎么形容。
每当我点击箭头时,它应该转换到另一个箭头。无需翻转、旋转等,只需简单变换即可。
如果不够准确,欢迎评论!
演示代码
struct ContentView: View {
@State private var change = false
private let arrowWidth: CGFloat = 80
var body: some View {
Path { path in
path.move(to: .zero)
path.addLine(to: CGPoint(x: arrowWidth/2, y: change ? -20 : 20))
path.move(to: CGPoint(x: arrowWidth/2, y: change ? -20 : 20))
path.addLine(to: CGPoint(x: arrowWidth, y: 0))
}
.stroke(style: StrokeStyle(lineWidth: 12, lineCap: .round))
.frame(width: arrowWidth)
.foregroundColor(.green)
.animation(.default)
.onTapGesture { change.toggle() }
.padding(.top, 300)
}
}
你现在可以看到它没有动画。我不知道该怎么做。
非常感谢任何帮助。谢谢!
注意:我不能用两个圆角矩形 + 简单地旋转来做到这一点,因为我有一个不透明动画,这使得重叠可见。
【问题讨论】:
标签: ios swift animation swiftui