Goal c How to set UserInteractionEnabled: NO for all view except UIButton in this view

In my application, I have an idea that I have many UIElements, buttons, etc.

I need to install

UserInteractionEnabled: NO for all ui elements in this view exceptone button.

I tried using

 [self.view setUserInteractionEnabled:NO];

The “Require” button also refers to the fact that self.view this button also applies the same behavior.

I can apply individually, but this is not very good.

How to set UserInteractionEnabled: NO for all other ui elements except one

+4
source share
3 answers
for (UIView *view in [self.view subviews])
    {
        if (view.tag==101)
            [ view setUserInteractionEnabled:YES];
        else
            [ view setUserInteractionEnabled:NO];
    }
+2

:

for (UIView *view in self.view.subviews) {
    if (!([view class]==[UIButton class]) )
    {
        view.userInteractionEnabled = NO;
    }
}
+1

You can simply add a transparent subview in front of your view and place a button on that transparent view:

UIView* maskView = [[UIView alloc] initWithFrame:self.view.bounds];
maskView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:maskView];
[maskView addSubview:buttonView];

And make sure that this transparent view is the last subview added or just clicks it on the front of viewWillAppear:

[self.view bringSubviewToFront:maskView];
+1
source

All Articles