iOS7 Xcode utility app - UINavigationBar on Flipsi

2019-02-07 15:42发布

I have this issue, where as standard the flipsideviewcontroller UINavigationBar looks like this:

Weird Layout

Anybody have any ideas on how to move the UINavigationBar either down, or to stop the ugliness of it all?

1条回答
太酷不给撩
2楼-- · 2019-02-07 16:02

It's tricky. :) You need to set a delegate for the UINavigationBar - this will probably be the FlipsideViewController. You can do this in the storyboard, or in code - for example, if you have an outlet to the navigation bar:

-(void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBar.delegate = self;
}

Now comes the important part: implement in the delegate this method:

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

With auto layout, it is also crucial that the top of the navigation bar have a zero-constant constraint to the Top Layout Guide. This is not entirely easy to set up because there is a bug in Xcode that will try to turn this into a bad constraint from the bottom of the navigation bar. If that happens:

  • Delete the top constraint.

  • Move the nav bar down the screen.

  • Control-drag to form the top constraint to the Top Layout Guide again.

  • Now select the top constraint and manually set its Constant to 0, to make the nav bar move back up again.

查看更多
登录 后发表回答