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

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

$
0
0

You can do it using this code my views which are imageviews in the xib.

- (void)viewDidLoad{    firstIV.tag = 501;    secondIV.tag = 502;    thirdIV.tag = 503;    forthIV.tag = 504;    [self addTapGesturetoImageView: firstIV];    [self addTapGesturetoImageView: secondIV];    [self addTapGesturetoImageView: thirdIV];    [self addTapGesturetoImageView: forthIV];}-(void)addTapGesturetoImageView:(UIImageView*)iv{    iv.userInteractionEnabled = YES;    UITapGestureRecognizer * textfielBGIVTapGasture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(textfielBGIVTapped:)];    textfielBGIVTapGasture.numberOfTapsRequired = 1;    [iv addGestureRecognizer:textfielBGIVTapGasture];}- (void)textfielBGIVTapped:(UITapGestureRecognizer *)recognizer {    int tag = recognizer.view.tag-500;    switch (tag) {        case 1:        {            //firstIV tapped;            break;        }        case 2:        {            //secondIV tapped;            break;        }        case 3:        {            //thirdIV tapped;            break;        }        case 4:        {            //forthIV tapped;            break;        }        default: {            break;        }    }}

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>