I have 20+ buttons and I want to define a single UILongPressGestureRecognizer for all, is it possible?
So far this doesn't work:
let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture))
B_BTN_1.addGestureRecognizer(longPressGestureRecognizer)
B_BTN_2.addGestureRecognizer(longPressGestureRecognizer)
For some reason, the longPressGestureRecognizer only works for "B_BTN_2".
But by declaring a gesture recognizer for each, it works:
let longPressGestureRecognizer1 = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture))
let longPressGestureRecognizer2 = UILongPressGestureRecognizer(target: self, action: #selector(handleLongGesture))
B_BTN_1.addGestureRecognizer(longPressGestureRecognizer1)
B_BTN_2.addGestureRecognizer(longPressGestureRecognizer2)
EDIT:
If you'll gonna use @Andre's solution, and having many buttons, use this instead to prevent the indexing bug (takes like forever):
var buttons:[UIButton] = []
buttons.append(B_BTN_1)
buttons.append(B_BTN_2)
buttons.append(B_BTN_3)
.....