Question

I have a view controller which contains a scrollview, which takes up the whole available window. There is a UIView which I use as a container view, which is a subview of the scrollview, and contains all the other views and controls. There is a lot of configuration when the view controller is initialized, as to what view(s) and control(s) will be displayed, depending on the data from the web service.

Attached to the main view of the view controller is a tap gesture recognizer. I've found that I need to check [touch view] to see if it is either a button or any other control that I don't want the gesture recognizer to interpret, and pass a NO value back from the

  • (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

delegate method if it is once of these controls.

So in this container view is another (UIView ) subview, and in that subview is a button. The view controller is part of a navigation controller stack, and all works well when this is presented as simply a navigation controller.

When the navigation controller is presented from one tab of a tab bar, then when I tap the button it isn't recognizing the tap on that button. When I break in the delegate method above, [touch view] is a UIView, and not a UIButton.

If I tap and hold on the button for a second or so, then it does recognize the button, and forwards the message to the button.

Any thoughts on this? I can post code, just not sure what to post yet...

Was it helpful?

Solution

Maybe the button is outside the bounds of its containing view? If clipsToBounds isn't set, the button will still appear, but since it is outside the bounds of its superview it won't respond to touches.

Another possibility is that another view is overlapping the button. If the overlapping view has a transparent background, you won't be able to see where it overlaps but it could be stealing touch events from the view beneath it.

Any time I have a lot of nested views, I find the easiest way to see what's going on is to (temporarily) set the backgroundColor of each view to a different color. That way I can see exactly where the bounds of each view are, how they are nested, and what overlaps what.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top