0

I am trying to customize a UIPickerView

I have subclass a UIView which is mainView.

And there is a mask view for blur or darken background purpose, I added it to the mainView.

Then there is the picker view, I have added it to the mask view as subview.

The hierarchy is simple as

--mainview

| -- maskview

|| -- pickerview

Finally I add the whole view to application key window.

My question is, every time I show this mainview, I want mask view to block userinteractions therefore user can't click outside the picker view.

But if I set the userinteractive of mask view to no, it also block the picker view scrolls and touches.

So how can I implement the superview to be non interactive and it's subview to be interactive?

Thanks.

Mix
  • 459
  • 1
  • 7
  • 20

3 Answers3

0

1. Set superview to be non interactive:

Yoursuperview.userInteractionEnabled=NO;

2. Set subview to be interactive:

Then, iterate through subviews of your superview and set user interaction to YES like below:

for (UIView* view in YourSuperView.subviews) {

    if ([view isKindOfClass:[/*"which ever class of your subviews "*/ class]])

        [view setUserInteractionEnabled:YES];

}

OR

Set setUserInteractionEnabled to all subviews of your superview

for (UIView* view in YourSuperView.subviews) {

     [view setUserInteractionEnabled:YES];

}

OR

Yoursuperview.userInteractionEnabled=NO;

[[yourSuperView subviews]makeObjectsPerformSelector:@selector(setUserInteractionEnabled:) withObject:[NSNumber numberWithBool:FALSE]];

Check here for more information: https://stackoverflow.com/a/11546963/5575752

Community
  • 1
  • 1
Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
0

By default, if your mask view is pure UIView, when you make an interaction with it, there is nothing happened. Otherwise, let add another pure UIView on top of your custom mask view.

--mainview

| -- customView user can interaction(your old mask view if it is a custom one)

|| -- maskview

||| -- pickerview

Trung Phan
  • 923
  • 10
  • 18
0

Set the hierarchy up like the following:

--mainview

| -- maskview

| -- pickerview

Now you can set the userInteractionEnabled to NO on the maskview without blocking the pickerview. The picker view must be below the maskview in the document outline in order to be in front of the maskview.