disable elements on UIView behind modal UIView
Asked Answered
W

2

2

i have a UIView that is smaller than the superview so i can represent this view as a modal view when a button is clicked.

I have managed to do the following: * add a subview to the superview. * centered this modal view

I am now trying to make the elements behind the UIView unclickable. And also add a grey shadow te the ourside of my modal view so that the user understands that the modal view is the view in focus.

I would like to know how to achieve this.

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

Wasteful answered 7/1, 2011 at 13:21 Comment(0)
S
11

The simplest thing would be to lay a fullscreen UIView with a translucent gray background behind your "modal" view. Then it will intercept all of the 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 on a view.

Schreiber answered 7/1, 2011 at 17:13 Comment(0)
S
0

There are several ways to do it. If you have a custom view which has custom location, you can modify it like that:

Create an instance var:

UIView* backgroundView;

And whenever you need it, put it behind your custom view:

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];

When you do not need it anymore

   [backgroundView removeFromSuperview];
Salomon answered 5/12, 2013 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.