Search code examples
iosobjective-cuiviewuinavigationbarmainscreen

How to display a UIView which overlaps the UINavigationBar


In my application, I want to initiate a UIView that overlaps and dims the whole screen including the UINavigationBar, the code is as below:

- (void)showInstruction
{
    self.holedView = [[JMHoledView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.view addSubview:self.holedView];
}

but indeed the self.holedView can only dims the district without the UINavigationBar on the screen. How can I do that?


Solution

  • You can add view as a subview to the window's or navigation controller's view.

    [self.navigationController.view addSubview:yourView];
    

    OR

    [[[[UIApplication sharedApplication] delegate] window] addSubview:yourView];
    

    Create view's delegate to remove it from superview whenever needed