我想在基于狀態變數有條件地呈現或洗掉文本視圖時為其設定影片。
我試過了,沒有用
struct AnimatedText: View {
@State var showingText = false
var body: some View {
VStack {
if showingText {
Text("Hello world")
.animation(.easeInOut, value: showingText)
}
Button("Toggle") {
showingText.toggle()
}
}
}
}
如何為文本視圖設定影片?
uj5u.com熱心網友回復:
出現/消失是由容器影片的,所以你需要Text放入一些容器中并使其具有影片效果,比如
var body: some View {
VStack {
VStack {
if showingText {
Text("Hello world")
}
}.animation(.easeInOut, value: showingText) // << here !!
Button("Toggle") {
showingText.toggle()
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/421734.html
標籤:
