2

Below code is implemented using viewController can i do same thing for Apple Watch and add animation?

let filteredSubviews = self.view.subviews.filter({ $0.isKindOfClass(UIImageView) })// 2
    for view in filteredSubviews  {
        // 3
        let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTap:"))
        recognizer.numberOfTapsRequired=1
        // 4
        recognizer.delegate = self
        view.addGestureRecognizer(recognizer)
        returnedAray=tempArray
        //TODO: Add a custom gesture recognizer too
    }

I just need to know what is alternative of addGestureRecognizer(recognizer) for WatchKit.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
Samrez Ikram
  • 591
  • 5
  • 15

2 Answers2

6

You can not use gesture recognizers in Watch applications.

But you can use WKInterfaceButton with context "Group" instead of "text":

enter image description here

So button will contain any group and you can implement action on tapping.

Example:

enter image description here

enter image description here

Button contains group with image and label.

KepPM
  • 1,129
  • 7
  • 17
  • please answer relevant to question :/ – Samrez Ikram Mar 03 '15 at 06:08
  • 2 Samrez Ikram: It is impossible to use gesture recognizers. WKInterfaceObject is NOT a UIResonder or UIView. But you can create a BIG WKInterfaceButton (fullscreen, transparent, e.t.c.) and handle tapping on button. Choose context = "Group" and fill any content to this group :) – KepPM Mar 03 '15 at 10:32
  • You also can use WKInterfaceTable and handle tapping on cell with -(void)table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex – KepPM Mar 03 '15 at 11:59
2

You can't do gesture recognizers or touch events in an Apple Watch App.

Stephen Johnson
  • 5,293
  • 1
  • 23
  • 37
  • so what can we do for tapping in WatchKit? – Samrez Ikram Mar 03 '15 at 04:00
  • You can add buttons and tables to your Watch App and respond to the user tapping on the button or table cell. You can also add a menu to your app that is activated on a force press. Remember that the code for Watch Apps are not native apps. They are extensions running on an iPhone. The actual Watch App is just UI. – Stephen Johnson Mar 03 '15 at 14:06