title: UICollectionView How to implement horizontal align scrolling
body: <p>I have a <code>UICollection</code> which is implemented and works, however I cannot achieve the scrolling I want.</p>
  
  <p>Here is a picture of my <code>UICollectionView</code>, I have resized the grey cell to <code>250</code> by <code>250</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/QHoWc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QHoWc.png" alt="enter image description here"></a></p>
  
  <p>My issue is, when I start scrolling, this is what happens. </p>
  
  <p>My cell first starts off on the far left, but notice what happens if I start to scroll horizontally.</p>
  
  <p><a href="https://i.stack.imgur.com/AN1f4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AN1f4.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/aACAg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aACAg.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Ygh2K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ygh2K.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the seam between the cells moves over to the left the more I scroll through the cells. This is not what I want. </p>
  
  <p>What I want to achieve is: the cell is aligned to the center, and when you scroll, instead of the center of the cells moving to the left more and more, I want the cell to stay in the middle. Much like a <code>PageViewController</code> does except I want it to be <code>UICollectionViewCells</code>. </p>
  
  <p>I have tried adding in the following code for example:</p>
  
  <pre><code>    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
  {
      float pageWidth = 210;
  
      float currentOffset = scrollView.contentOffset.x;
      float targetOffset = targetContentOffset-&gt;x;
      float newTargetOffset = 0;
  
      if (targetOffset &gt; currentOffset)
          newTargetOffset = ceilf(currentOffset / pageWidth) * pageWidth;
      else
          newTargetOffset = floorf(currentOffset / pageWidth) * pageWidth;
  
      if (newTargetOffset &lt; 0)
          newTargetOffset = 0;
      else if (newTargetOffset &gt; scrollView.contentSize.width)
              newTargetOffset = scrollView.contentSize.width;
  
          targetContentOffset-&gt;x = currentOffset;
          [scrollView setContentOffset:CGPointMake(newTargetOffset, 0) animated:YES];
      }
  </code></pre>
  
  <p>Which achieves the even scrolling, however I want to have <code>paging</code> enabled aswell as <code>bounce</code>. </p>
  
  <p><a href="https://i.stack.imgur.com/ilEqE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ilEqE.png" alt="enter image description here"></a></p>
  
  <p>Because if I enable <code>paging</code> and <code>bounce</code>, the scrolling is very smooth and elegant, however If I use the code up above the scrolling is very rugged and mechanical.</p>
  
  <p>So How can I achieve even scrolling that is smooth like apples default scrolling, with my <code>UICollectionViewCell</code> being centred in the middle?</p>
  
  <p>If I didn't explain the problem well enough, this post <a href="https://stackoverflow.com/questions/13228600/uicollectionview-align-logic-missing-in-horizontal-paging-scrollview">here</a> explains my problem except I am using one cell instead of three, and I want the scrolling to be smooth and bounce etc.</p>