I have an app where the UINavigationBar has not adapted to iOS7 positioning and I'm stuck on how to get it to position correctly.
I'm not using Auto Layout but have attached a screenshot of the issue I'm getting:
I have an app where the UINavigationBar has not adapted to iOS7 positioning and I'm stuck on how to get it to position correctly.
I'm not using Auto Layout but have attached a screenshot of the issue I'm getting:
In your view controller implement positionForBar: method
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar {
return UIBarPositionTopAttached;
}
Make self as toolbar delegate and maybe you have to move your toolbar down by 20 pt.
The new stuff on iOS7 uses a full screen layout, if you want to put your navigation bar on top you need to implement the UIBarPositioningDelegate
in this way:
-(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
if ([bar isKindOfClass:[UINavigationBar class]]) {
return UIBarPositionTopAttached;
}
return UIBarPositionAny;
}
Don't forget to assign the delegate of your navigation bar to the class that implements this method, i.e.
//self should be the controller that implements the above method.
myNavigationBarReference.delegate = self;
P.S. UINavigationBarDelegate
, UIToolBarDelegate
inherit the UIBarPositioningDelegate
.
Try to add the following code in viewDidLoad: method
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
May it solve your issue. Happy coding!!
You can adopt Auto Layout incrementally programmatically just where it is needed. And do you add a navigationBar to your view instead of using navigationController? If so, you can add several lines to solve your problem.
id topGuide = self.topLayoutGuide;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (topGuide, yourNavigationBar);
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topGuide]-0-[yourNavigationBar]"
options:0
metrics:nil
views:viewsDictionary];
[self.view addConstraints:constraints];
And if not the case, please let me know your implementation.