ios - Crop UIImageView and gesture recognizer -
i have imageview crop circle this:
self.contentmode = uiviewcontentmodescaleaspectfill; self.layer.cornerradius = self.bounds.size.height / 2.0; self.layer.maskstobounds = yes;
then added gesture recognizer it, fires in cropped area.
how can avoid firing in cropped area?
- set class conforms
uigesturerecognizerdelegate
- set gesture delegate self
then use delegate decide if want fire or not
-(bool) gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldreceivetouch:(uitouch *)touch
example code
-(bool)gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldreceivetouch:(uitouch *)touch{ cgpoint touchpoint = [touch locationinview:self.imageview]; if (cgrectcontainspoint(self.imageview.bounds, touchpoint)) { cgfloat centerx = cgrectgetmidx(self.imageview.bounds); cgfloat centery = cgrectgetmidy(self.imageview.bounds); cgfloat radius2 = pow((touchpoint.x -centerx),2)+ pow((touchpoint.y - centery), 2); if (radius2 < pow(cgrectgetwidth(self.imageview.frame)/2, 2)) { return yes; } } return no;}
Comments
Post a Comment