It appears that userInteractionEnabled=NO on a parent view will prevent user interaction on all subviews. Is this correct? Is there any way around this?
I just ran into an odd situation. I have a UIView (call this, V), which has a UIButton as a subview. Call this UIButton, button X. Below is the method I'm using for the target/selector of button X. self below is the view V. The sender parameter is button X.
The situation that's causing me an issue is that if I touch another button on my UI (on the nav bar, call this button Y) and then very quickly touch button X, where the the button Y action disables view V, I still get the touch event sent to button X.
- (void) buttonAction: (UIButton *) sender
{
NSLog(@"superview: %d", sender.superview.userInteractionEnabled);
NSLog(@"button itself: %d", sender.userInteractionEnabled);
//
}
Here's the output:
2014-12-19 16:57:53.826 MyApp[6161:960615] superview: 0
2014-12-19 16:57:53.826 MyApp[6161:960615] button itself: 1
That is, the button action occurred and the button's superview had user interaction disabled! And the subview still had user interaction enabled!!
For those of you thinking that this seems artificial, on my app's UI, running on an iPad (running iOS 8.1.2), this came up by accident in my use of the app. It was not something I was originally trying to generate.
Thoughts?
My current workaround is given below, but it seems really odd that it's necessary!
- (void) buttonAction: (id) sender
{
NSLog(@"superview: %d", sender.superview.userInteractionEnabled);
NSLog(@"button itself: %d", sender.userInteractionEnabled);
if (! self.userInteractionEnabled) return;
//
}