I have created a UICollectionView and would like to have all the cells shake like the edit mode of the springboard on the iPhone. I have created my shake code but don\'t kno
Updated to swift 3 syntax:
let animationRotateDegres: CGFloat = 0.5
let animationTranslateX: CGFloat = 1.0
let animationTranslateY: CGFloat = 1.0
let count: Int = 1
func wobble() {
let leftOrRight: CGFloat = (count % 2 == 0 ? 1 : -1)
let rightOrLeft: CGFloat = (count % 2 == 0 ? -1 : 1)
let leftWobble: CGAffineTransform = CGAffineTransform(rotationAngle: degreesToRadians(x: animationRotateDegres * leftOrRight))
let rightWobble: CGAffineTransform = CGAffineTransform(rotationAngle: degreesToRadians(x: animationRotateDegres * rightOrLeft))
let moveTransform: CGAffineTransform = leftWobble.translatedBy(x: -animationTranslateX, y: -animationTranslateY)
let conCatTransform: CGAffineTransform = leftWobble.concatenating(moveTransform)
transform = rightWobble // starting point
UIView.animate(withDuration: 0.1, delay: 0.08, options: [.allowUserInteraction, .autoreverse], animations: { () -> Void in
self.transform = conCatTransform
}, completion: nil)
}
func degreesToRadians(x: CGFloat) -> CGFloat {
return CGFloat(M_PI) * x / 180.0
}