objective c - iOS Add tap Gesture to UIImageView -
i have image inside uiimageview, has gesture zooming, can see code.
i want able insert clickable areas of image, not screen, if click image point minimum or maximum zoom zoom return same value.
i tell uigesturerecognizer if can do? why can not figure out whether work or not.
thanks
my code:
uitapgesturerecognizer *twofingertap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletwofingertap:)]; [twofingertap setnumberoftouchesrequired:2]; [img addgesturerecognizer:twofingertap]; float minimumscale = 0.4;//this minimum scale, set whatever want. 1.0 = default scroll.maximumzoomscale = 4.0; scroll.minimumzoomscale = minimumscale; scroll.zoomscale = minimumscale; [scroll setcontentmode:uiviewcontentmodescaleaspectfit]; [img sizetofit]; [scroll setcontentsize:cgsizemake(img.frame.size.width, img.frame.size.height)]; [control setselectedsegmentindex:0]; [control addtarget:self action:@selector(action:) forcontrolevents:uicontroleventvaluechanged]; //this recognizer on image uigesturerecognizer *recognizerimage = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapimage:)]; [(uitapgesturerecognizer *)recognizer setnumberoftapsrequired:2]; [img addgesturerecognizer:recognizer]; } - (void)tapimage:(uitapgesturerecognizer *)recognizer { cgpoint location = [recognizer locationinview:self.view]; nslog(@"x %f y %f",location.x, location.y); }
try using imageview reference:
cgpoint location = [recognizer locationinview:recognizer.view];
let me know if works.
Comments
Post a Comment