A UIImageView
is
derived from a UIView
which
is derived from UIResponder
so
it's ready to handle touch events. You'll want to provide the touchesBegan
, touchesMoved
,
andtouchesEnded
methods
and they'll get called if the user taps the image. If all you want is a tap event, it's easier to just use a custom button with the image set as the button image. But if you want finer-grain control over taps, moves, etc. this is the way to go.
You'll also want to look at a few more things:
-
Override
canBecomeFirstResponder
and return YES to indicate that the view can become the focus of touch events (the default is NO). -
Set the
userInteractionEnabled
property to YES. The default forUIViews
is YES, but forUIImageViews
is NO so you have to explicitly turn it on. -
If you want to respond to multi-touch events (i.e. pinch, zoom, etc) you'll want to set
multipleTouchEnabled
to YES.