Quantcast
Channel: Can you attach a UIGestureRecognizer to multiple views? - Stack Overflow
Viewing all articles
Browse latest Browse all 14

Answer by kwalker for Can you attach a UIGestureRecognizer to multiple views?

$
0
0

I got around it by using the below.

for (UIButton *aButton in myButtons) {            UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];            longPress.minimumPressDuration=1.0;            [aButton addGestureRecognizer:longPress];            [longPress release];}

Then in my handleLongPress method I just set a UIButton equal to the view of the gesture recognizer and branch what I do based upon that button

- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture {    if ( gesture.state == UIGestureRecognizerStateEnded ) {        UIButton *whichButton=(UIButton *)[gesture view];        selectedButton=(UIButton *)[gesture view];    ....}

Viewing all articles
Browse latest Browse all 14

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>