Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Below is the simplest way that I've found to get this effect. It involves your collection view and an extra secret scroll view.</p> <p><strong>Set up your collection views</strong></p> <ul> <li>Set up your collection view and all its data source methods.</li> <li>Frame the collection view; it should span the full width that you want to be visible.</li> <li><p>Set the collection view's <code>contentInset</code>:</p> <pre><code>_collectionView.contentInset = UIEdgeInsetsMake(0, (self.view.frame.size.width-pageSize)/2, 0, (self.view.frame.size.width-pageSize)/2); </code></pre></li> </ul> <p>This helps offset the cells properly.</p> <p><strong>Set up your secret scrollview</strong></p> <ul> <li>Create a scrollview, place it wherever you like. You can set it to <code>hidden</code> if you like.</li> <li>Set the size of the scrollview's bounds to the desired size of your page.</li> <li>Set yourself as the delegate of the scrollview.</li> <li>Set its <code>contentSize</code> to the expected content size of your collection view.</li> </ul> <p><strong>Move your gesture recognizer</strong></p> <ul> <li><p>Add the secret scrollview's gesture recognizer to the collection view, and disable the collection view's gesture recognizer:</p> <pre><code>[_collectionView addGestureRecognizer:_secretScrollView.panGestureRecognizer]; _collectionView.panGestureRecognizer.enabled = NO; </code></pre></li> </ul> <p><strong>Delegate</strong></p> <pre><code>- (void) scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint contentOffset = scrollView.contentOffset; contentOffset.x = contentOffset.x - _collectionView.contentInset.left; _collectionView.contentOffset = contentOffset; } </code></pre> <p>As the scrollview moves, get its offset and set it to the offset of the collection view.</p> <p>I blogged about this here, so check this link for updates: <a href="http://khanlou.com/2013/04/paging-a-overflowing-collection-view/" rel="noreferrer">http://khanlou.com/2013/04/paging-a-overflowing-collection-view/</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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