I have a problem with autolayout(maybe) and my scrollview!
My Problem
- I scroll down
2.Then I push to another View
3.Then I go back and the scrollview looks like that and I'm not able to scroll to the highest point.(I see it in the bouncing of the scrollview)
Can anybody help me?
try this
The issue cause ScrollView was set ContentOffset before AutoLayout applied. the solution is:
Create private property
Add code to view method
The following code snippet in the containing view controller also seems to solve the problem, without relying on explicit sizes:
It does reset the content offset to the origin, but it seems that so do the other answers.
I had the same problem. Turned out I was setting a constraint on the content view aligning the it's y-center to the superview's y-center. When I deleted this constraint it worked just fine.
I was using adam's solution, but started to have problems when i was dismissing with animated:YES. In my code, content offset gets set a while after viewWillAppear (as viewWillAppear appears to be too soon).
EDIT: another, better way is to reset it back in viewDidLayoutSubviews :)
This isn't great but I beat auto-layout (definitely not the correct way but I was sick of trying!) by setting the content size in viewDidAppear after autolayout happens, setting the scrollOffset and persisting the scroll offset in viewDidDisappear, and then setting the scroll offset back to it's persisted state in viewDidAppear.
Like this:
Not at all elegant, but works so thought I'd share.