我有一个测试代码来显示这个问题,当我使用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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
Asp*_*eri 15
.transition(.opacity)这是从视图层次结构中删除(插入)视图时应用的默认效果。
我假设你需要线性尺度过渡,比如
if start {
Circle()
.foregroundColor(Color.black)
.matchedGeometryEffect(id: "Circle", in: animationNamespaceon)
.transition(.scale(scale: 1))
.frame(width: 300, height: 300)
}
else {
Circle()
.foregroundColor(Color.black)
.matchedGeometryEffect(id: "Circle", in: animationNamespaceon)
.transition(.scale(scale: 1))
.frame(width: 50, height: 50)
}
Run Code Online (Sandbox Code Playgroud)
使用 Xcode 13 / iOS 15 进行测试
| 归档时间: |
|
| 查看次数: |
1790 次 |
| 最近记录: |