我可以为插入视图和删除视图指定不同的转换:
.transition(
.asymmetric(
insertion: .move(edge: .leading)
removal: .move(edge: .trailing)
)
)
这很好用.然而,我希望它这么容易在快速,当它被添加,并缓解缓慢时删除.尽管编译得很好,但下面的代码似乎没有做任何事情.
.transition(
.asymmetric(
insertion: .move(edge: .leading)
.animation(.easeIn(duration: 2)),
removal: .move(edge: .trailing)
.animation(.easeOut(duration: 5))
)
)
我是否误解了.animation
作为过渡修饰语的用法?
演示代码:
struct TestView: View {
@State private var showDetails = false
var body: some View {
VStack {
Button("Press to show details") {
withAnimation {
showDetails.toggle()
}
}
if showDetails {
Text("Details go here.")
.background(Color.blue)
.transition(
.asymmetric(
insertion: .move(edge: .leading)
.animation(.easeIn(duration: 5)),
removal: .move(edge: .trailing)
.animation(.easeOut(duration: 5))
)
)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}