User Interaction on a UIImageView
I have a number of UIImageView which have buttons on top of them.
I would like to enable user interaction on the UIImageView behind these buttons.
I see the option in IB, but would like to know how to trigger some code when the UIImageView is actually touched.
How does one do this and how is it set to enabled and disabled in the code rather开发者_JS百科 than IB?
Thanks
how to trigger some code when the UIImageView is actually touched.
You have two options:
Create an instance of
UITapGestureRecognizer
(or another gesture recognizer), specifying a target and an action method. Then add the gesture recognizer to the image view with-[UIView addGestureRecognizer:]
. Works in OS 3.2+.Subclass
UIImageView
and override the-touches...
methods. Make sure the image views you create are instances of your custom subclass.
See the documentation for details.
how is it set to enabled and disabled in the code rather than IB
Simple: imageView.userInteractionEnabled = YES;
精彩评论