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
canBecomeFirstResponderand return YES to indicate that the view can become the focus of touch events (the default is NO). -
Set the
userInteractionEnabledproperty to YES. The default forUIViewsis YES, but forUIImageViewsis 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
multipleTouchEnabledto YES.
本文介绍了如何使用 UIImageView 处理触摸事件,包括设置相应属性使 UIImageView 能够响应触摸事件,以及实现 touchesBegan、touchesMoved 和 touchesEnded 方法来具体处理触摸事件。文中还提到了多点触摸的支持。
11万+

被折叠的 条评论
为什么被折叠?



