1

For an iphone project with an "unique" design (with which i am not happy at all) I need to draw a custom view which partially overlaps the navigation bar of a controller in a UINavigationController. Target is iphone/ios 6 with a fixed device orientation (portrait).

My currents solution is to disable the navigation bar programatically via self.navigationController.navigationBar.hidden = YES; in viewDidLoad of my controller and to draw a "fake" navigation bar and paint over this. This leads to the problem that the status bar color remains black (since there is no real navigation bar visible). Ios 6 status bar color is discussed here: Status bar color in iOS 6?

I already tried to use [self.view insertSubview:OVERLAPVIEW aboveSubView:self.navigationController.navigationBar] but it did not work and OVERLAPVIEW was drawn beneath the navigation bar.

Is there another way to overlap the navigation bar with another view (z-wise)? Or is there a way to change the status bar color when no navigation bar is shown (unfortunately in addition to this the view with the overlap is the main view of the app and the first screen visible to the user)

Full disclosure: I am an ios noob and stack overflow lurker - this is my first question on stack overflow, please help me to clarify my question and improve my stack overflow skills if necessary.

Community
  • 1
  • 1
iosGoblin
  • 31
  • 1
  • 6
  • Which color do you need the status bar to be? – Jan S. Jan 02 '13 at 03:25
  • Most other screens have a navigation bar and the color adapted to the color of these navigation bars (pinkish). I use `[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque];` in my AppDelegate.m in order to set the color to black on all screens. Nevertheless i fear that the client might request that the color schould be pink so i would like to be prepared (an i am generally curious why there is no way to set the status bar color and why we would need a navigation bar in order to get any color) – iosGoblin Jan 02 '13 at 09:46
  • You can change the tint color of the status bar. If you go to your Project Summary there is an option to set its tint color. You could make it pink. – Jan S. Jan 03 '13 at 02:32
  • This option seems to only set the color during startup - the rest of the time an average of pixels of the navigation bar is used see: http://www.cultofmac.com/173928/how-ios-6s-cool-new-adaptive-status-bar-works/ and http://stackoverflow.com/questions/12467794/how-to-set-status-bar-tint-color-on-ios-6 – iosGoblin Jan 03 '13 at 10:09

3 Answers3

5

Use

[self.navigationController.view addSubview:OVERLAPVIEW];

instead of

[self.view insertSubview:OVERLAPVIEW aboveSubView:self.navigationController.navigationBar];

You can adjust the frame of your view according to make navigation bar partially visible.

Anusha Kottiyal
  • 3,855
  • 3
  • 28
  • 45
  • Thanks for the answer - as far as i can tell this is a valid solution. In my case the view which overlaps the navigation bar is of the size of an entire screen (there is a flap to "pull in" an additional view) and i am reluctant to add all of this to the navigation bar. I will try it and will report back any findings/problems. – iosGoblin Jan 02 '13 at 09:50
  • The solution seems to work - but since my view needs to overlap the navigation bar and it has some elements which need interactions i also need to make the frame of the navigation bar bigger. I do this by simple creating a bigger frame and set it as the navigation bar frame. Nevertheless http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationBar_Class/Reference/UINavigationBar.html states that we are not allowed to set the frame of a navigation bar. – iosGoblin Jan 02 '13 at 10:23
  • @iosGoblin You said that your view needs to overlap the navigation bar . Then why you change the frame of navigation bar? Your elements are in the OVERLAPVIEW no? – Anusha Kottiyal Jan 02 '13 at 11:38
  • Yes my elememts are in the OVERLAPVIEW, but it seems i am not able to interact with these elements if they are outside of the frame of the navigation bar (in which they are contained now) – iosGoblin Jan 02 '13 at 12:12
  • Did you set OVERLAPVIEW.userInteractionEnabled = YES; ?? – Anusha Kottiyal Jan 02 '13 at 12:15
  • yes the userInteraction is Enabled (it is a scrollview with some buttons resembling a tabbar at the bottom). As i said I think i can only interact with it when the frame of the navbar (in which it is contained) is big enough to allow the interaction. – iosGoblin Jan 02 '13 at 12:40
1

I solved this issue by hiding the Navigation bar with

self.navigationController.navigationBar.hidden = YES;

and by adding a navigation bar to my view. Everything added after this new navigation bar will to overlap it (you could use index [parentView.subviews objectAtIndex:0]; as well). The color of the status bar changes as needed.

In the case of the splash screen i do exactly the same and overlap the navigation bar with the fullscreen splash image.

-(void)viewDidLoad{
    [super viewDidLoad];
    UINavigationBar * navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 49)];
    UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"SPLASH"];
    [navigationBar pushNavigationItem:item animated:NO];
    [self.view addSubview:navigationBar];

    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.y -= 20;
    UIImageView *splashImage = [[UIImageView alloc] initWithFrame:frame];
    splashImage.image = [UIImage imageNamed:@"splash"];
   [self.view addSubview:splashImage];
}
iosGoblin
  • 31
  • 1
  • 6
0

It seems that this answer solves my issue Add UIView Above All Other Views, Including StatusBar

Note: at the moment i am not going down this road and I will accept this answer once I tried it (I postponed solving this problem at the moment and it might take a while)

Community
  • 1
  • 1
iosGoblin
  • 31
  • 1
  • 6