简体   繁体   中英

Is there any way to access pressesbegan method on WKInterfaceButton

I have a WKInterfaceButton in Xcode and when I configure the action for it, it only executes it when the tap has ended, that is, when my finger is lifted.

@IBAction func kickButton() {
       //Action for this button
}

I want to be able to perform the same action but when the touch has just started, like the pressesBegan action in iOS applications. I don't know if there is a way to do this.

You could replace your button with a tap gesture recognizer and then target a function similar to this:

func handlePress(sender: WKTapGestureRecognizer) {
    if sender.state == .began {
        // code for when press began
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM