Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView wrong offset with Auto Layout
    primarykey
    data
    text
    <p>I have a fairly simple view configuration:</p> <p>A <code>UIViewController</code>, with a child <code>UIScrollView</code> and a <code>UIImageView</code> in this <code>UIScrollView</code>. I set the <code>UIImageView</code> with a height sufficient to break out of the visible area (ie. higher to <code>1024pt</code>), and set the <code>Bottom space to superview</code> constraint of my <code>UIImageView</code> to a fixed positive value (<code>20</code> for example).</p> <p><img src="https://i.stack.imgur.com/tVR63.png" alt="project layout"></p> <p>The whole setup works as expected, the image scrolls nicely in its parent. Except when the view is scrolled (the effect is more visible if you scrolled to the bottom of the view), then disappear, and appear again (you switched to another view and came back) the scrolling value is restored, but the content of the scroll view is moved to the outside top part of its parent view.</p> <p>This is not simple to explain, I'll try to draw it: <img src="https://i.stack.imgur.com/ttH5w.png" alt="visual representation of previous paragraph"></p> <p>If you want to test/view the source (or the storyboard, I did not edit a single line of code). I put a little demo on my github: <a href="https://github.com/guillaume-algis/iOSAutoLayoutScrollView" rel="nofollow noreferrer">https://github.com/guillaume-algis/iOSAutoLayoutScrollView</a></p> <p>I did read the <a href="http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/index.html" rel="nofollow noreferrer">iOS 6 changelog</a> and the explanation on this particular topic, and think this is the correct implementation of the second option (pure auto layout), but in this case why is the <code>UIScrollView</code> behaving so erratically ? Am I missing something ? </p> <p><strong>EDIT</strong>: This is the exact same issue as <a href="https://stackoverflow.com/questions/12580434/uiscrollview-autolayout-issue">#12580434 uiscrollview-autolayout-issue</a>. The answers are just workarounds, as anyone found a proper way to fix this or is this a iOS bug ?</p> <p><strong>EDIT 2</strong>: I found another workaround, which keep the scroll position in the same state the user left it (this is an improvement over <a href="https://stackoverflow.com/questions/12580434/uiscrollview-autolayout-issue">12580434</a>'s accepted answer):</p> <pre><code>@interface GAViewController () @property CGPoint tempContentOffset; @end @implementation GAViewController -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.tempContentOffset = self.mainScrollView.contentOffset; self.scrollView.contentOffset = CGPointZero; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.scrollView.contentOffset = self.tempContentOffset; } </code></pre> <p>This basically save the offset in <code>viewWillAppear</code>, reset it to the origin, and then restore the value in <code>viewDidAppear</code>. The problem seems to occur between these two calls, but I can't find its origin.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload