spstanley
spstanley

Reputation: 950

Navigation bar with prompt appears over the view with new iOS7 SDK

I've made sure my navigation bar is not translucent and I've added this to my viewDidLoad so my navigation bar with prompt does not overlap my view when it first appears:

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

This works great until I navigate to a view controller with a navigation bar that has no prompt, then pop back. When the navigation bar with prompt is redisplayed, the navigation bar extends downward to its full size (after viewDidAppear is invoked!) using some internal animation and my view is partially overlapped by the 30 pixel difference. Any ideas on what I can do about that?

Upvotes: 1

Views: 1398

Answers (2)

spstanley
spstanley

Reputation: 950

I hate solutions like this. But my work-around is for iOS7 only, compare the view's frame.origin.y to the navigation bar's frame.origin.y + frame.size.height, in viewDidAppear. If they're different, I resize and reposition the view, animating so it doesn't look stupid. The view also has a scroll view as a subview, so I have to tweak that a bit too:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
        CGRect nbFrame = self.navigationController.navigationBar.frame;
        __block CGRect vFrame = self.view.frame;
        __block CGFloat diff = nbFrame.size.height + nbFrame.origin.y - vFrame.origin.y;
        if (diff > 0.0) {
            __block CGSize size = scrollView.contentSize;
            [UIView animateWithDuration:UINavigationControllerHideShowBarDuration
                                  delay:0.0
                                options: UIViewAnimationOptionCurveEaseOut
                             animations:^{
                                 vFrame.origin.y += diff;
                                 vFrame.size.height -= diff;
                                 self.view.frame = vFrame;

                                 size.height -= diff;
                                 scrollView.contentSize = size;
                             }
                             completion:^(BOOL finished){
                                 NSLog(@"Done!");
                             }];
        }
    }
}

Upvotes: 2

CodeCracker
CodeCracker

Reputation: 459

If you have not used the autolayout.Try to set delta for that.

Upvotes: 1

Related Questions