Events are not Visible on UIImageView - iphone

I have a UIImageView, and a referencing outlet. However, altough I've set User Interaction of the ImageView, I cannot see any event in IB. Is it normal or am I missing something?

UIImageView is not a kind of UIControl, so you cannot set events to it. You have to use a UIButton with background, or subclass UIImageView and override the -touchesBegan: methods.

Related

Disabling/Enabling IBOutlet determines if I get touches or not?

I'm trying to overlay a transparent image over my app, with the purpose of explaining the controls of that view. When the UIImageView is first touched it should simply disappear. My MainViewController has the touchesBegan/Ended methods implemented and they work fine until I connect the UIImageView to an IBOutlet in MainViewController. Simply stop responding to events. What am I doing wrong?
-MainView
--ScrollView
--OtherView
--UIImageView (this is the overlay)
UIImageViews do not have user interaction turned on by default. If you want it on, either set the property via IB, User Interaction Enabled or via code...
[myImageView setUserInteractionEnabled:TRUE];

iPhone SDK - Touch a UIButton through a UILabel

I am trying to capture a touch through a UILabel, but am having trouble. Here is my scenario.
I have a UIButton as a subview of a UIScrollView. I also have a UILabel as a subview of the same UIScrollView. The frame of the UILabel overlaps that of the UIButton, and thus (as far as I can tell) occludes the UIButton from being pressed.
I am trying to create a scenario where the user can touch through the UILabel (it has a transparent background, so the button is completely visible - less the labels text).
Is this possible?
I know touches behave differently when there is a UIScrollView involved. Is that impeding the touches?
Anyone have any advice?
Cheers,
Brett
myLabel.userInteractionEnabled = NO;
Creating transparent UIButton on top of UILabel that too inside a UIScrollView is a design issue for me. If you have to do it then you don't have a choice. It won't work seamlessly though. Don't expect users not to complain. If I don't see a button there and scrolling through the view accidentally triggers button action then I am irritated.
It is possible to create such UI.

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 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;

UIButton in CALayer

How can I add a UIButton in a CALayer and hookup the touch event?
A CALayer is not an event responder, so trying to hook it up to a touch event handler will do nothing.
If you want a button that actually works on top of a CALayer, put that CALayer into a UIView (which is a subclass of UIResponder), and add a UIButton to that view (so it can get added to the event response chain).
In iOS, all UIViews own and draw themselves through a CGLayer. You probably want to create a UIView for your button to go in. Everything you can do with raw CGLayers, you can do with UIViews.

transparent subview over UIimageView

as i am a new in iphone world ,i need some startup help to achieve this kind of design? background of view which has button should be transparent so that user can see product image in back.
http://www.freeimagehosting.net/uploads/cb58b72480.jpg
let me know if it requires more explanation?
thanks.
You will have to have a single UIView containing your UIImageView and UIButton.
Using InterfaceBuilder first drag the UIImageView and then drag the UIButton inside the parent UIVIew.
Or programmatically you can call the parent UIView's addSubView method first for the UIImageView and then for the UIButton view
[view addSubview:myImageView]
[view addSubview:myButton]
Either of this approach will place the instance UIButton on top of the UIImageView when the UIView is rendered
Also, FYI, transparency of a View can be controlled through its alpha property
alpha = 0 being the most transparent and
alpha = 1 being the most opaque
Hope this helps.