I have a UIImageView
whose 'View Mode' is set to 'Aspect Fit' in Interface Builder.I want to add gesture recognizer to only my image inside of the UIImageView
.To clarify what i say:
I have a UIImageView
whose bounds.size.width = 100;
and bounds.size.height = 100;
and I have a UIImage
whose size is 100x50. So, when I add my UIImage
to my UIImageView
there exists some spaces of 25 from top and 25 from bottom. But I don't want to recognize user's tap when he/she taps on these spaces. I just want to know when user tapped on UIImage
.
How can I do that?
As
UIImage
extends fromNSObject
you can not addUITapGestureRecognizer
to it, you have to add gesture to theUIImageView
itself. Then in any of theUIGestureRecognizer
delegate methods:or
get touch's location in
UIImageView
. Then by usingCGPoint location = [_gesture locationInView:yourImageView]
get the touched point, now get the image's frame using this link. Now check if the point is in Image's frame or not by using:This might help you.