Overlap navigation bar on ios 6 with other view

谁说胖子不能爱 提交于 2019-12-11 06:24:18

问题


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.


回答1:


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.




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



回答3:


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)



来源:https://stackoverflow.com/questions/14115240/overlap-navigation-bar-on-ios-6-with-other-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!