문제

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.

도움이 되었습니까?

해결책 2

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

다른 팁

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.

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top