SwiftUI: how to handle BOTH tap & long press of button?

前端 未结 8 1226
刺人心
刺人心 2020-12-15 06:59

I have a button in SwiftUI and I would like to be able to have a different action for \"tap button\" (normal click/tap) and \"long press\".

Is that possible in Swift

8条回答
  •  盖世英雄少女心
    2020-12-15 07:58

    I tried many things but finally I did something like this:

        Button(action: {
        }) {
            VStack {
                Image(self.imageName)
                    .resizable()
                    .onTapGesture {
                        self.action(false)
                    }
                    .onLongPressGesture(minimumDuration: 0.1) {
                        self.action(true)
                    }
            }
        }
    

    It is still a button with effects but short and long press are different.

提交回复
热议问题