Search code examples
iosswiftwatchkit

WkLongPressGestureRecognizer


I dragged two gestures to my storyboard: One a tap gesture and the other a long press gesture.

Just to test it out, I set them up with something simple:

@IBAction func gestureDblTap(_ gesture: WKTapGestureRecognizer )  {

    print("hello world")

}

@IBAction func gestureHoldDown(_ gesture: WKLongPressGestureRecognizer ) {

    print("Holding down")

}

The double tap gesture works but the long press doesn't work. I've set it to 1 tap, 0.5 second and movement is 10.

I've implemented UILongPressGestureRecognizer on iOS and it worked...I don't see why it shouldn't on WatchKit, since it's basically replacing UILongPressGestureRecognizer with WKLongPressGestureRecognizer.

Any suggestion what I could try to get it to work?


Solution

  • I ended up solving it by creating a Group and putting my gestures under that group:

    @IBOutlet var gestureGroup: WKInterfaceGroup!
    
    @IBAction func gestureDblTap(_ gesture: WKTapGestureRecognizer )  {
    
        print("hello world")
    
    }
    
    @IBAction func gestureHoldDown(_ gesture: WKLongPressGestureRecognizer ) {
    
        print("Holding down")
    
    }
    

    That worked.

    enter image description here

    The rest of the programming is just like in iOS.