【发布时间】:2021-12-10 13:36:16
【问题描述】:
我有一个测试代码来显示这个问题,当我使用matchedGeometryEffect 时,matchedGeometryEffect 会在渲染结果中添加一个不希望出现的淡入淡出效果,所以我喜欢移除这个淡入淡出效果甚至控制它。当我将视图的颜色从一种颜色更改为另一种颜色时可能是一件好事,但在我的情况下它并不好,因为颜色一直都是黑色的。
struct ContentView: View {
@Namespace var animationNamespaceon
@State private var start: Bool = Bool()
var body: some View {
VStack {
Spacer()
circle
Spacer()
Button("update") { start.toggle() }
}
.animation(Animation.linear(duration: 3), value: start)
}
@ViewBuilder var circle: some View {
if start {
Circle()
.foregroundColor(Color.black)
.matchedGeometryEffect(id: "Circle", in: animationNamespaceon)
.frame(width: 300, height: 300)
}
else {
Circle()
.foregroundColor(Color.black)
.matchedGeometryEffect(id: "Circle", in: animationNamespaceon)
.frame(width: 50, height: 50)
}
}
}
【问题讨论】: