Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView child jumping after UINavigationController push and pop

So I have a UIScrollView on my iPad app with a single child view (which itself is parent to all the controls). The scrolling all works fine on it. Rotating works fine (the whole view fits in portrait, scrolls on landscape). Once pushing a new screen on the UINavigationController, and then coming back breaks it.

It looks as if the frame of the scrollview's child has moved up, relative to the scroll position, but the scrollview has remained at the bottom (the entire child view has shifted upwards).

I've tried fighting the Constraints in storyboard, literally for hours, and cannot work out what could be causing this.

How it startsHow it looks like after navigating and returning

like image 693
Dan2552 Avatar asked Nov 13 '22 17:11

Dan2552


1 Answers

I had the same problem with scroll view and auto layouts (iOS 6 - doesn't work, iOS 7 - works fine), of course this is not perfect solution, but seems like it works. Hope it will help you:

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

    [self performSelector:@selector(content) withObject:nil afterDelay:0.0];
}

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

    offset = self.scrollView.contentOffset;
}

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

   self.scrollView.contentOffset = CGPointZero;
}

- (void)content
{
    [self.scrollView setContentOffset:offset animated:NO];
}
like image 182
Ned Avatar answered Dec 19 '22 06:12

Ned