1

I have a view in scrolling view, and when I seque(push) from this ViewController to CommentViewController, and came back, view in scroll view moved for 200 px up, I dont know why, I don`t anything in code.

-(void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  [scroller setScrollEnabled:YES];
  [scroller setContentSize:CGSizeMake(320, 2000)];
}

Its when Auto Layout is on. When it off, its work, but design is not impressive... Can I fix it with Auto Layout?

  • Probably related to this bug: http://stackoverflow.com/questions/18048514/shifting-view-after-displaying-modal-possibly-autolayout-related Try to add the constraints that layout the views inside your scrollview to the superview of the scrollview instead. – Matthias Bauch Aug 21 '13 at 09:31

1 Answers1

0

Here's a quick fix

In viewWillDisappear, save the scrollView's contentOffset and reset it to zero.
Later in viewDidLayoutSubview, restore the contentOffset to old value.

Here's the sample code

-(void) viewDidLayoutSubviews
{
 [super viewDidLayoutSubviews];
 if(!CGPointEqualToPoint(CGPointZero, self.contentOffset))
 {
    scroller.contentOffset = self.contentOffset;
    self.contentOffset = CGPointZero;
 }
}


-(void) viewWillDisappear:(BOOL)animated
{
 [super viewWillDisappear:animated];
 self.contentOffset = scroller.contentOffset;
 scroller.contentOffset = CGPointZero;
}
Suraj
  • 101
  • 6