Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView adjusts contentOffset when contentSize changes
    primarykey
    data
    text
    <p>I am adjusting a detail view controller's state, just before it is pushed on a <code>navigationController</code>:</p> <pre><code>[self.detailViewController detailsForObject:someObject]; [self.navigationController pushViewController:self.detailViewController animated:YES]; </code></pre> <p>In the <code>DetailViewController</code> a scrollView resides. Which content I resize based on the passed object:</p> <pre><code>- (void)detailsForObject:(id)someObject { // set some textView's content here self.contentView.frame = &lt;rect with new calculated size&gt;; self.scrollView.contentSize = self.contentView.frame.size; self.scrollView.contentOffset = CGPointZero; } </code></pre> <p>Now, this all works, but the scrollView adjusts it's <code>contentOffset</code> during the navigationController's slide-in animation. The <code>contentOffset</code> will be set to the difference between the last contentSize and the new calculated one. This means that the second time you open the detailsView, the details will scroll to some unwanted location. Even though I'm setting the <code>contentOffset</code> to <code>CGPointZero</code> explicitly.</p> <p>I found that resetting the <code>contentOffset</code> in <code>- viewWillAppear</code> has no effect. The best I could come up with is resetting the contentOffset in <code>viewDidAppear</code>, causing a noticeable up and down movement of the content:</p> <pre><code>- (void)viewDidAppear:(BOOL)animated { self.scrollView.contentOffset = CGPointZero; } </code></pre> <p>Is there a way to prevent a <code>UIScrollView</code> from adjusting its <code>contentOffset</code> when its <code>contentSize</code> is changed?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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