[英]Why SwiftUI view transitions modifiers don't work?
I needed to add a view to my scene using a view transition.我需要使用视图转换将视图添加到我的场景中。 I was trying to use the modifier
.transition(.opacity)
but it just adds the view without any transition.我试图使用修饰符
.transition(.opacity)
但它只是添加了没有任何过渡的视图。 I also tried the other transition types and they don't work.我还尝试了其他过渡类型,但它们不起作用。 Since this is a really simple test project a don't see where's the issue.
由于这是一个非常简单的测试项目,因此不知道问题出在哪里。 Here's a link to a video of my problem
这是我的问题视频的链接
import SwiftUI
struct Test: View {
@State var show = false
var body: some View {
VStack {
Button(action: {self.show.toggle()}) {
Text("Button")
}
if show {
Text("Test Text")
.transition(.move(edge: .top))
}
}
}
}
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
}
}
You need to add animation for the transition您需要为过渡添加动画
if show {
Text("Test Text").animation(.linear)
.transition(.move(edge: .top))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.