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?

  1. set class conforms uigesturerecognizerdelegate
  2. set gesture delegate self
  3. 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

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -