0

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?

Julie Yu
  • 83
  • 1
  • 6

4 Answers4

2

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

Rashad
  • 11,057
  • 4
  • 45
  • 73
Ashwani
  • 378
  • 1
  • 3
  • 13
  • Or as the comment said, add myview to self.view.window; there are some differences and I'm trying to figure it out... – Julie Yu May 06 '15 at 08:20
1

You can use dimmed transparent image and set it as background image of navigation bar.

For eg In my case , I made black transparent image of alpha 0.2 and set it as navigation background image and made the background color clear color

 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"black_patch.png"]
                                              forBarMetrics:UIBarMetricsDefault];
[UINavigationBar appearance].translucent = YES;
navController.view.backgroundColor = [UIColor clearColor];
Mukesh
  • 3,680
  • 1
  • 15
  • 32
0

I use this to add subView in the main window:

[[UIApplication sharedApplication].keyWindow addSubview:view];
Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64
0

you can add it to the window

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication  sharedApplication] delegate];
UIView *backgrView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
backgrView.backgroundColor = [UIColor blackColor];
backgrView.alpha = 0.6;
[[appDelegate window] addSubview:backgrView];

or

Try navigationBar.translucent = NO; , It is YES by default in iOS7.


 So you can add a version check like this:

 float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (systemVersion >= 7.0)
{
 navigationBar.translucent = NO;
}
Shanmugasundharam
  • 2,082
  • 23
  • 32