Disable items in a UIView behind a modal UIView

I have a UIView that is smaller than a supervisor, so I can present this view as a modal view when a button is clicked.

I managed to do the following: * add a preview to the supervisor. * centered this modal view

Now I'm trying to make the elements behind the UIView invisible. And also add a gray shadow to the side of my modal view, so that the user understands that the modal view is the focus in focus.

I would like to know how to achieve this.

I do not want to use a presentation modal transition. I know and have already implemented this in other projects. Any help is appreciated.

+2
objective-c iphone background
Jan 07 2018-11-11T00:
source share
2 answers

The simplest task would be to place a full-screen UIView with a translucent gray background behind your β€œmodal” view. Then he will intercept all touches. It might look something like this:

 UIView *dimBackgroundView = [[UIView alloc] initWithFrame:theSuperview.bounds]; dimBackgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f]; [theSuperview addSubview:dimBackgroundView]; [theSuperview addSubview:modalView]; 

For future reference, you can set myView.userInteractionEnabled = NO to disable touch events in the view.

+10
Jan 07 '11 at 17:13
source share

There are several ways to do this. If you have a custom view that has a custom location, you can change it as follows:

Create an instance of var :

 UIView* backgroundView; 

And whenever you need it, put it on your own look:

 if (backgroundView == nil) backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width)]; backgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f]; [self.view addSubview:backgroundView]; [backgroundView animateBump:customView.view]; [backgroundView addSubview:customView.view]; 

If you don’t need it anymore

  [backgroundView removeFromSuperview]; 
0
Dec 05 '13 at 11:55 on
source share



All Articles