Superview ignores UserInteractionEnabled = NO?

I have a subview that appears animated on the screen, and when it is on the screen, I want the supervisor (in my case, the view in the background) to ignore touch events. I tried everything, but it did not work.

Is there a way to make the “supervisor” stop accepting touch events?

Thanks!

+6
source share
1 answer

When you say supervisor, I assume that you mean an animated view viewview. Apple's documentation is very non-specific regarding userInteractionEnabled , but I think that if you set it to false, it will disable touch events on a specific view, but not on its subview. I suggest you do it recursively. The following is an example of code that can be used to disable / enable all touch events in a view:

 - (void)setInteraction:(BOOL)allow onView:(UIView *)aView { [aView setUserInteractionEnabled:allow]; for (UIView * v in [aView subviews]) { [self setInteraction:allow onView:v]; } } 

You can then call this in your supervisor [self setInteraction:NO onView:[self superview]] . Of course, this will also disable your touch events, since you will disable them recursively in your supervisor. Of course, you can always activate your touch events [self setUserInteractionEnabled:NO] .

In addition, Apple 's UIView class reference indicates that some user interface components override this method:

Note : some UIKit subclasses override this property and return a different default value. See the documentation for any class that you use to determine if it returns a different value for this property.

+4
source

Source: https://habr.com/ru/post/894451/


All Articles