UITextField subview of UIImageView is not responding to touch events - ios

I have a UITextField that responds to touch events when it is added as a subview of self.view. When I add it as a subview of a UIImageView it does not respond to touch events any more. I make it a firstResponder and the field is active and takes keyboard input still. Any ideas what is wrong?

The docs for UIImageView state:
New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.
Try setting imgView.userInteractionEnabled = YES
If this doesn't work, I would try adding the UIImageView and the UITextField in a UIView instead. Anyway, this approach seems cleaner.

Related

Exclusive touch on UIControl

I have an UIButton and UISwitch. A user could touch both with one finger each at the same time and release - triggering 2 separate TouchUpInside #IBActions.
How can I tell a control that it's touches must be exclusive, without creating a subclass?
UIControl is subclass of UIView so you can directly set exclusiveTouch = true on any UI control.

ios uibutton hidden: does this automatically make the button disabled?

I just have a knowledge question about UIButtons / iOS in general.
Let's say you have a UIButton. You set the 'hidden' property to YES. This makes it no longer visible in view, right? But I noticed that while it's no longer visible, it is also no longer clickable either. So, does this mean that setting hidden = YES also sets enabled = NO?
Just curious. Thanks y'all.
UIButton and all controls inherits common properties from UIView like hidden, backgroundColor, etc.
Class reference of UIView says if any view is hidden then it will not receive input events
Class reference of UIView says:
A hidden view disappears from its window and does not receive input
events. It remains in its superview’s list of subviews, however, and
participates in autoresizing as usual. Hiding a view with subviews has
the effect of hiding those subviews and any view descendants they
might have. This effect is implicit and does not alter the hidden
state of the receiver’s descendants.
you can find this over Here.
It does. Setting the buttons hidden property to YES will disable any user interaction. This is true for other UI elements as well as just UIButton.
Yes you can't touch button when it is hidden.If you wanna touch it then you must make it btn.hidden = NO;. Hidden means disable the user interaction.
Not sure. Best way to find out would be an NSLog returning button.hidden

Button as subview, click start superview

I have a button that will be a subview added to a another UIView, like Path does. The idea is that this button will remain static in one corner of the screen while the user can scroll through the UIVIew behind it.
I am handling the pointsinside method, to know when a user clicks whether it was on the button or the super view.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return CGRectContainsPoint(customButton.frame, point);
}
My question is, if the user does click in the button, I need to open up a UIImagePickerController, which is a property of the superview. how can I do that on the superview though?
Thanks.
you should add an event to button by addTarget method.
If the button is Guaranteed (and I mean that, because it will crash without a guarantee) to be the subview of the superview you mention, then casting self.superview will allow you access to it's UIImagePickerController property. A much safer implementation would use a weak reference to the owning superview, then property manipulation would fail gracefully if you tried to re-use the button without it's superview.

Objective-C - addToSubview but do not intercept touches

Is there a way you can add a UIView without the view intercepting touches? I tried insertSubview: belowSubview
The reason I want to do this is because I'm adding a UITextField to a UITableViewCell's contentView. But I don't want the UITextField intercepting the touches when I select a row. I know I can set the UITextField userInteractionEnabled property to NO but this leads to a lot of micro management.
Override canBecomeFirstResponder to return NO.
See this info on the Responder Chain.

iPad - UIImageView respond to touch

In MonoTouch how do I get a UIImage or UIImageView to fire off a delegate or something when clicked?
Exactly as Dimitris pointed out, you'll want to subclass UIImageView, and also ensure that the userInteractionEnabled flag is set to true.
I should point out that in most cases where people intend to have a UIImageView respond to interaction, these problems can just as easily be fixed by creating a UIButton instance with an image instead.
You have to subclass it (the UIImageView) and override one of TouchesBegan, TouchesMoved or TouchesEnded methods, according to what you want to do.

Resources