These are my troubleshooting steps when a part of my UI isn’t responding to touch events.
Is there a view covering your view?
If there is, then move it! This often happens due to breaking constraints or ambiguous layout causing a view to shift over yours unexpctedly.
Is your parent view properly sized?
When subclassing or instantiating a plain old
clipsToBounds defaults to
backgroundColor defaults to
clear. This may cause your view to look correct, even though it’s internal structure is not actually laid out correctly. Its possible your containing view has a height or width of zero, meaning it is not actually sending touches to its children. Fix this by updating your layout to ensure parent views have a non-zero height and width.
Is there a UIGestureRecognizer in a parent intercepting your touches?
If there is, you may need to implement a method in
UIGestureRecognizerDelegate to ensure touches make it to your view. The method
func gestureRecognizer(UIGestureRecognizer, shouldReceive: UITouch) -> Bool will allow you to check if the touch should route to your view instead of the parent. One way to test this if you have found the parent
UIGestureRecognizer toggle its
Does all the view’s parents have
userInteractionEnabled = true?
If not, then toggle it!
Does your view have a parent?
If not, add it to the view hierarchy!
If your using a UIGestureRecognizer, Did you add it to the UIView?
If not, add it with
This is not a conclusive list of all reasons why your UI is not receiving touches, but these are all things that happen to me often when trying to build a new UI! Hope this helps!