Hibernia Hibernia - 2 months ago 14
iOS Question

Adding gestures to a draggable view? Swift

I've got

buttons
on my
view
that are
draggable
using
touches
began/moved/ended.
I want to add a
tapped
and
doubletapped
actions for my
buttons
. Once I switch my button's class to
UIButton
the action I've created works, but once I change it back to
DraggableView
the actions stop being called because I guess touchesBegan overrides any other touches on the view.

Is there a good way to do this?

Answer

First of all you have to implement UITapGestureRecogizer delegate in your class and add following line of code.

let tap = UITapGestureRecognizer(target: self, action: "handleTap:")
tap.delegate = self
tap.numberOfTapsRequired = 1
yourButton.addGestureRecognizer(tap)

Hope this helps.