I have a UIViewController
subclass as a scene in the storyboard that contains a UIScrollView
containing various subviews. One of the subviews is a UIButton
which segues into another scene UIViewController
subclass. When I come back from the view (pop the UIViewController
off the navigation controller stack), I find that the scroll view's origin has somehow changed, although the contentsize
and contentoffset
seem correct.
What's also interesting is that the app has a tab bar, and when I tab away and back to that view, the scroll view is set back correctly with offset at (0, 0).
There is basically no code involved in this process, as it's pretty much all in the storyboard. As I am fairly new to using the storyboard, I figure I'm doing something wrong, although I don't know what. Any ideas as to what that may be? Perhaps sizing issues or constraints?
recently , I have encountered this bug, can be solved using these codes:
thanks Peter Jacobs!
In iOS 7/8/9 simple
self.automaticallyAdjustsScrollViewInsets = NO;
solved the problem in my case.None of the above worked for me, I managed to do my own custom Push/Pull animation instead and it works like a charm.
First, add this class which implements Push scenario
Then add this class which implements pop scenario
Then add this line to your viewDidLoad method to change default NavigationController Delegate
And see the magic :)
Continued Issue when following the current answers:
The second attempt to open the presented view controller, without having left the presenting view controller, the problem remained. Which is why I am posting the exact steps that resulted in my solution.
So, I reset the collectionView's constraints in the Storyboard, making certain they were pinned to presentingViewController's main view.
Added:
self.view.translatesAutoresizingMaskIntoConstraints = YES;
inside theviewDidLoad
of the presenting view controller.And stored, privately, the contentOffset of the collection view prior to the modally presented view controller's appearance:
I have fixed this ios6 bug , can be solved using these codes. I solved bug occurred in Scrollview. Thank above all my friends!
Unfortunately, Peter and MacMark's suggestions did not work for me (Xcode 5 w/ auto-layout). The solution was to go to the storyboard, select the view controller, and
Reset to Suggested Constraints in View Controller
.