2

I've got a UIScrollView on my main ViewControler. When it initially loads from startup the UIScrollview is placed correctly but when I go to a modal view and then dismiss that modal view the UIScrollView shifts up several pixels from the position that my UIScrollView was at when I loaded the modal view (the amount of shift seems to be relative to the position of the UIScrollView). So in other words if my UIScrollView was all the way to the top it loads correctly if I was scrolled all the way to the bottom when I go to a modal view and then go back it seems to have shifted up approximately 20 to 30 pixels cutting the top of the content off in my UIScrollView.

I cant figure out why its loading differently depending on the amount I've scrolled before loading the modal view.

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGFloat scrollFrameHeight = [[UIScreen mainScreen] applicationFrame].size.height;
    CGFloat scrollFrameWidth = [[UIScreen mainScreen] applicationFrame].size.width;

    scrollView.frame = CGRectMake(0, 0, scrollFrameWidth, scrollFrameHeight);
}

FYI... I've tried using static numbers in place of my variables and I still get the strange shift.

Old Name
  • 273
  • 1
  • 3
  • 13
  • Any custom behaviour in `viewDidAppear` method? – Nikola Kirev Jun 22 '13 at 21:11
  • No. And oddly... I removed the above code from the viewDidLoad and my scrollview still loads and scrolls as it did when the code was there? I also removed the contentSize code and it is still loading and scrolling! I thought it should have failed without the code! – Old Name Jun 22 '13 at 21:32
  • Seems to have something to do with autolayout in Xcode. If I'm using autolayout I don't need the above code but I get the shift. If I turn off autolayout I need the code but I don't get the shift. – Old Name Jun 22 '13 at 21:40
  • The more I mess with it the more I think it's a bug with autolayout. – Old Name Jun 22 '13 at 22:03
  • anyone figure this out? really odd behaviour. I'm having the same problem. – khanh.tran.vinh Jul 08 '13 at 01:59
  • Here is a demo project - is it the same issue? http://stackoverflow.com/questions/18048514/shifting-view-after-displaying-modal-possibly-autolayout-related – Ben Packard Aug 04 '13 at 23:12

0 Answers0