简体   繁体   中英

iOS7: UINavigationBar merges with status bar

I am new to iOS and the situation I am in in following

  • I have a UIViewController that has UITableView and UINavigationBar as
 @interface CategoryGroupViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> @property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar; @property (strong, nonatomic) IBOutlet UITableView *tableView; @end 

In XIB it looks like

在此处输入图片说明

When I run my application, it looks like

在此处输入图片说明

I looked around solutions online, and also tried setting

self.edgesForExtendedLayout = UIRectEdgeNone;

But this doesn't seem to resolve the issue. Can someone please guide as to what I am missing?

Thank you

Follow below steps to use default Navigationbar with NavigationContoller.

so your flow is UIWindow > UINavigationController > UIViewController.

in appDidFinishlaunching

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainscreen].bounds];
self.vc = [[CategoryGroupViewController alloc]initWithNibName:@"CategoryGroupViewController" bundle:nil];
self.navC = [[UINavigationController alloc]initWithRootViewController:self.vc];
self.navC.navigationBar.translucent = NO;
self.window.rootViewController = self.navC;
[self.window makeKeyAndVisible];

Now run your application and you will get 64px navigationbar. if you want to title that viewcontroller then

in CategoryGroupViewController's viewDidLoad

self.title = @"Pick Group";

if you want to hide this navigationbar then simply use code in perticular controller. but once you hide then navigationbar will hide in whole app. so you have to manage it manually.

self.navigationController.navigationBarHidden = YES;

Maybe this will help you.

From iOS 7 and onwards , Apple has restricted use of Status bar and navigation bar. I mean it is transparent now.

There are still ways to achieve our goals.

Way 1: We can use a navigation bar image of 64 px (128 in @2x resolution). It will automatically colorise our navigation bar and status bar as well.

Way 2 : We can opt another solution

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;

You need add the above in your -(void)viewDidLoad method.

Thanks

Assuming you are explicitly intending to use your own navigation bars and not those provided by a UINavigationController, you need to add the top layout guide into consideration. Right now your bar is being constrained to the top of the view where instead it needs to take into consideration the height of the status bar. You also want to be able to respond to the status bar extending (like when you are in a call). These constraints would do the trick

id topGuide = self.topLayoutGuide;
UINavigationBar *navBar = self.navigationBar

//navBar.top == self.view.top
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[navBar]"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:NSDictionaryOfVariableBindings (navBar)]];

//pin navBar to horizontal edges
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[navBar]|"
                                                                      options:0
                                                                      metrics:nil
                                                                        views:NSDictionaryOfVariableBindings (navBar)]];

//navBar.bottom = statusBar.bottom + 44
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:navBar
                                                          attribute:NSLayoutAttributeBottom
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:topGuide
                                                          attribute:NSLayoutAttributeBottom
                                                         multiplier:1.f
                                                           constant:44]];

I was facing the same problem. But resolved my problem by increasing delta y position of view .

在此处输入图片说明

Check out the above screen shot.you can add delta y position like this. This worked for me. Hope it would work for you. Try this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM