lgvv98

SwiftUI .swipeActions not working 본문

apple/Docs, iOS, Swift

SwiftUI .swipeActions not working

lgvv 2024. 8. 28. 00:35

[SwiftUI] .swipeActions not working

 

When using swipeActions, it does not work if you place a other content instead of a Button.​

swipeActions interface

 

 

❌ It does not work

    @State private var showTranslation = false

    var body: some View {
        List(0..<5) {
            Text("\($0)")
                .swipeActions(edge: .trailing, allowsFullSwipe: true) {
                    Image(systemName: "plus") // ❌
                }
        }
        .listStyle(.plain)
        .translationPresentation(
            isPresented: $showTranslation,
            text: "테스트"
        )
    }
}

 

✅ It works

    @State private var showTranslation = false

    var body: some View {
        List(0..<5) {
            Text("\($0)")
                .swipeActions(edge: .trailing, allowsFullSwipe: true) {
                    // ✅
                    Button {
                        showTranslation.toggle()
                    } label: {
                        Image(systemName: "plus")
                    }
                }
        }
        .listStyle(.plain)
        .translationPresentation(
            isPresented: $showTranslation,
            text: "테스트"
        )
    }
}

'apple > Docs, iOS, Swift' 카테고리의 다른 글

Swift @TaskLocal  (3) 2024.08.28
Swift KeyPath 정리  (0) 2024.08.28
iOS Translation Framework  (0) 2024.08.28
swift @_spi (System Programming Interfaces)  (0) 2024.08.20
CloudKit 정리 코드 예제 #3  (0) 2024.08.18
Comments