Question

I have UIView that open with a UIButton click. I want to disable user interaction of all other superviews except to this specific view and his subviews, how can I do that? Just to make this view the only view that will response to user touch.

Thanks!

Was it helpful?

Solution

Agree with the comment, you probably want to disable all siblings of a view... (edited so you can set them back to enabled at some point)

- (void)setSiblings:(UIView *)view enabled:(BOOL)enabled {

    for (UIView *sibling in view.superview.subviews) {
        if (sibling != view) sibling.userInteractionEnabled = enabled;
    }
}

OTHER TIPS

I know you already accepted an answer but a better (and easier) approach is to display the new view full screen. Make the new view with a clear background. Then add the real view as a subview to this full screen view. This way you don't have to mess with any existing views to display this new view. You can still see everything behind it but touch events are blocked by the clear, fullscreen view.

Then when you remove this full screen view (fade out animation?) you don't have to mess with all the existing views again.

You shouldn't have to modify existing views just to display another. And what happens if one of those existing views really should have its interaction disabled? You will end up enabling the interaction when you dismiss your "modal" view.

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