简体   繁体   中英

ios7 presentViewController reverts navBar from new 64px bar back to old 44px version

I have an application that is supporting only ios7+ The navbar setup is using the new 64px high bar that appears beneath the status bar. Here is what it looks like when the app launches:

在此处输入图片说明

If I do any sort of "presentViewController", when i dismiss the view the navbar shifts back to 44px height and still appears underneath the status bar which in-turn makes all the contents of the view also shift up. Here is what that looks like:

在此处输入图片说明

It doesn't matter if I am presenting one of my own views or if I simply present a UIImagePickerView, any sort of slide up modal via the navigation controller breaks the navbar setup. Any ideas on how to fix this?

A few notes:

  • in plist: "View controller-based status bar appearance" is set to "NO"
  • navbar configured with self.navController.navigationBar.translucent = NO;
  • I am using .xib NOT Storyboards

UPDATE:

I have the navigation controller inside of a PKRevealController ( https://github.com/pkluz/PKRevealController ). Taking the reveal controller out and just adding the nav controller to the window itself fixes the issue... why would the reveal controller cause it to behave differently?

SOLUTION:

It turned out that the PKRevealController library was causing the issue. I reworked how it was set up in the AppDelegate and that solved the problem, although it's sorta of "hacky". I put my "before" and "after" configurations below:

the initial setup was :

  1. configure PKRevealController
  2. configure NavController and add rootView
  3. set pkreveal front view = navController
  4. add reveal controller to window as windows root view

the fix is

  1. create a containing NavController
  2. do stpes 1-3 above
  3. add pkrevealcontroller to the containing navController
  4. set containing nav controller nav bar to hidden
  5. add containing nav controller to window as root view

If its navigationcontroller than you can use this inside every viewcontroller's viewdidload:

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

I had the same problem, but solved very easily by just setting the UINavigationBar Y-position to 20px and not to 0px. Then you have to assign the UINavigationBarDelegate to your ViewController:

[_navigationBar setDelegate:self];

Furthermore you have to add this method to your ViewController, which will be called because of the Delegate assignment:

-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
    return UIBarPositionTopAttached;
}

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