title: Circular UICollectionview, how to keep all cell angles 0°
body: <p>I build a circular UICollectionview by following <a href="https://www.raywenderlich.com/107687/uicollectionview-custom-layout-tutorial-spinning-wheel" rel="nofollow noreferrer">This</a> guide, Everything is working as expected but I don't want the items to rotate around their own angle/anchor</p>
  
  <p>The top row is how my circular collectionview is working at the moment, the bottom drawing is how I would like my collectionview :</p>
  
  <p><a href="https://i.stack.imgur.com/t768t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t768t.png" alt="Design"></a></p>
  
  <p>I am using following layout attribute code:</p>
  
  <pre><code>class CircularCollectionViewLayoutAttributes: UICollectionViewLayoutAttributes {
  
  var anchorPoint = CGPoint(x: 0.3, y: 0.5)
  
  var angle: CGFloat = 0 {
      didSet {
          zIndex = Int(angle*1000000)
          transform = CGAffineTransformMakeRotation(angle)
      }
  }
  
  override func copyWithZone(zone: NSZone) -&gt; AnyObject {
      let copiedAttributes: CircularCollectionViewLayoutAttributes = super.copyWithZone(zone) as! CircularCollectionViewLayoutAttributes
      copiedAttributes.anchorPoint = self.anchorPoint
      copiedAttributes.angle = self.angle
      return copiedAttributes
  }
  }
  </code></pre>
  
  <p>with the following layout class: </p>
  
  <pre><code>class CircularCollectionViewLayout: UICollectionViewLayout {
  let itemSize = CGSize(width: 60, height: 110)
  var angleAtExtreme: CGFloat {
  
      return collectionView!.numberOfItemsInSection(0) &gt; 0 ? -CGFloat(collectionView!.numberOfItemsInSection(0)-1)*anglePerItem : 0
  }
  
  var angle: CGFloat {
      return angleAtExtreme*collectionView!.contentOffset.x/(collectionViewContentSize().width - CGRectGetWidth(collectionView!.bounds))
  }
  
  var radius: CGFloat = 400 {
      didSet {
          invalidateLayout()
      }
  }
  
  var anglePerItem: CGFloat {
      return 0.18
  }
  
  var attributesList = [CircularCollectionViewLayoutAttributes]()
  
  override func collectionViewContentSize() -&gt; CGSize {
      return CGSize(width: CGFloat(collectionView!.numberOfItemsInSection(0))*itemSize.width,
                    height: CGRectGetHeight(collectionView!.bounds))
  }
  
  override class func layoutAttributesClass() -&gt; AnyClass {
      return CircularCollectionViewLayoutAttributes.self
  }
  
  override func prepareLayout() {
      super.prepareLayout()
      let centerX = collectionView!.contentOffset.x + (CGRectGetWidth(collectionView!.bounds)/2.0)
      let anchorPointY = ((itemSize.height/2.0) + radius)/itemSize.height
  
      let theta = atan2(CGRectGetWidth(collectionView!.bounds)/2.0, radius + (itemSize.height/2.0) - (CGRectGetHeight(collectionView!.bounds)/2.0)) //1
      //let theta:CGFloat = 1.0
  
  
      var startIndex = 0
      var endIndex = collectionView!.numberOfItemsInSection(0) - 1
  
      if (angle &lt; -theta) {
          startIndex = Int(floor((-theta - angle)/anglePerItem))
      }
  
      endIndex = min(endIndex, Int(ceil((theta - angle)/anglePerItem)))
  
      if (endIndex &lt; startIndex) {
          endIndex = 0
          startIndex = 0
      }
      attributesList = (startIndex...endIndex).map { (i) -&gt; CircularCollectionViewLayoutAttributes in
          let attributes = CircularCollectionViewLayoutAttributes(forCellWithIndexPath: NSIndexPath(forItem: i, inSection: 0))
          attributes.size = self.itemSize
          attributes.center = CGPoint(x: centerX, y: CGRectGetMidY(self.collectionView!.bounds))
          attributes.angle = self.angle + (self.anglePerItem*CGFloat(i))
          attributes.anchorPoint = CGPoint(x: 0.5, y: anchorPointY)
          return attributes
      }
  }
  
  override func layoutAttributesForElementsInRect(rect: CGRect) -&gt; [UICollectionViewLayoutAttributes]? {
      return attributesList
  }
  
  override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath)
      -&gt; (UICollectionViewLayoutAttributes!) {
          return attributesList[indexPath.row]
  }
  
  override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -&gt; Bool {
      return true
  }
  
  
  override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -&gt; CGPoint {
      var finalContentOffset = proposedContentOffset
      let factor = -angleAtExtreme/(collectionViewContentSize().width - CGRectGetWidth(collectionView!.bounds))
      let proposedAngle = proposedContentOffset.x*factor
      let ratio = proposedAngle/anglePerItem
      var multiplier: CGFloat
      if (velocity.x &gt; 0) {
          multiplier = ceil(ratio)
      } else if (velocity.x &lt; 0) {
          multiplier = floor(ratio)
      } else {
          multiplier = round(ratio)
      }
      finalContentOffset.x = multiplier*anglePerItem/factor
      return finalContentOffset
  }
  }
  </code></pre>
  
  <p>I tried many things but I was not able to change the cell rotation</p>