For the past couple of hours I have tried to accomplish the following:
In a UICollectionview when I highlight (touch down) a cell I want it to bounce inward a few pixels (to a smaller size) and on release bounce back to the original size.
Here is what I have tried so far:
override func collectionView(collectionView: UICollectionView,
didHighlightItemAtIndexPath indexPath: NSIndexPath) {
collectionView.collectionViewLayout.invalidateLayout()
let cell = collectionView.cellForItemAtIndexPath(indexPath)
UIView.transitionWithView(cell!, duration: 1, options: UIViewAnimationOptions.CurveEaseIn, animations: {
let center = cell?.center
let frame2 = CGRect(x: 0, y: 0, width: 50, height: 50)
cell?.frame = frame2
cell?.center = center!
}, completion: nil)
}
(I have found much of this code example from this question: UICollectionView: Animate cell size change on selection but this is applied on cell selection. Not highlight. )
So in the didHighlightItemAtIndexPath I set the highlighted cell to a new size. The size is set correct but the following problems arise: 1: it does not animate, 2: it moves to position (0,0) and animate back to center position. It should not move position at all - just the size.
I have seen this effect in the Shazam app for reference. It can be seen when you shazam a song (or view a previously shazamed song) on the buttons below the song name.