Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a strange undocumented behavior when rotating a paged <code>UIScrollView</code>.</p> <p>When the scrollview is positioned at the last page and the user changes the orientation, the OS scrolls the <code>UIScrollView</code> a few pixels back to compensate for the difference between height and width.</p> <p>Basically I received the following calls for any page.</p> <pre><code>willRotateToInterfaceOrientation:duration willAnimateRotationToInterfaceOrientation:duration: didRotateFromInterfaceOrientation: </code></pre> <p>And for the last page:</p> <pre><code>willRotateToInterfaceOrientation:duration scrollViewDidScroll: willAnimateRotationToInterfaceOrientation:duration: didRotateFromInterfaceOrientation: </code></pre> <p>That messed up with my pages too. The problem is that in <code>willRotate</code>, the bounds have not been updated by the OS yet, and in <code>willAnimate</code> you have the new bounds and can compute the new size, but it's too late...</p> <pre><code>- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { CGSize tempSize = [self.pagingScrollView contentSize]; NSUInteger padding = abs(pagingScrollView.frame.size.width - pagingScrollView.frame.size.height); tempSize.width += padding; [self.pagingScrollView setContentSize:tempSize]; [...] } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration{ CGSize newSize = ... // Compute new content size based on new orientation [self.pagingScrollView setContentSize:newSize]; } </code></pre> <p>This is just a workaround, but I spent countless hours on this issue and could not find an elegant solution.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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