簡體   English   中英

SwiftUI 編輯按鈕在 animation 之后不起作用

[英]SwiftUI Edit Button not working after animation

從組條件視圖制作動畫后,我列表上的編輯按鈕不起作用。 如果沒有 animation,它工作正常,但我不確定為什么 animation 會導致編輯按鈕不起作用?

struct Overview: View {
    @State var test = true
    var body: some View {
        Group {
            if test {
                Button(action: {
                    test = false
                }) {
                    Text("Button")
                }
            } else {
                NavigationView {
                    SimpleList()
                        .toolbar {
                            ToolbarItem(placement: .navigationBarTrailing) {
                                EditButton()
                            }
                        }
                }
                .navigationViewStyle(StackNavigationViewStyle())
            }
        }
        .animation(.easeOut, value: test)
    }
}

struct SimpleList: View {
    
    let test = ["1", "2", "3", "4"]
    var body: some View {
        List {
            ForEach(test, id: \.self) { t in
                Text(t)
            }
            .onDelete(perform: deleteRow)
        }
    }
    
    func deleteRow(_ :IndexSet) {
        
    }
}

不帶 animation: 沒有動畫

使用 animation: 帶動畫

將 .animation 從組移到導航視圖可解決此問題。 我將.animation 直接移到.navigationViewStyle 下並刪除了值:

在蘋果開發者論壇上回答:

https://developer.apple.com/forums/thread/698407

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM