ios - Adding gesture recognizer to UIImage, not UIImageView -


i have uiimageview 'view mode' set 'aspect fit' in interface builder.i want add gesture recognizer image inside of uiimageview.to clarify say:

i have uiimageview bounds.size.width = 100; , bounds.size.height = 100; , have uiimage size 100x50. so, when add uiimage uiimageview there exists spaces of 25 top , 25 bottom. don't want recognize user's tap when he/she taps on these spaces. want know when user tapped on uiimage.

how can that?

as uiimage extends nsobject can not add uitapgesturerecognizer it, have add gesture uiimageview itself. in of uigesturerecognizer delegate methods:

- (bool)gesturerecognizershouldbegin:(uigesturerecognizer *)gesturerecognizer; 

or

- (bool)gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldreceivetouch:(uitouch *)touch; 

get touch's location in uiimageview. using cgpoint location = [_gesture locationinview:yourimageview] touched point, image's frame using this link. check if point in image's frame or not using:

bool cgrectcontainspoint ( cgrect rect, cgpoint point ); 

this might you.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -