Search code examples
iphoneobjective-cbackgroundmodal-view

disable elements on UIView behind modal UIView


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.


Solution

  • 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.