Skip to content

Instantly share code, notes, and snippets.

@harryworld
Last active August 10, 2016 14:21
Show Gist options
  • Save harryworld/8524cc61bcc192beec92a4affafa5cc5 to your computer and use it in GitHub Desktop.
Save harryworld/8524cc61bcc192beec92a4affafa5cc5 to your computer and use it in GitHub Desktop.
Comparing iOS vs macOS animation
func animateView() {
CATransaction.begin()
CATransaction.setCompletionBlock { [unowned self] in
self.removeFromSuperview()
}
let rotationAtStart = view.layer?.valueForKeyPath("transform.rotation.x") as? NSNumber
let rotate = CABasicAnimation(keyPath: "transform.rotation.x")
rotate.duration = 0.3
rotate.fromValue = rotationAtStart
rotate.toValue = NSNumber(float: 0)
layer?.addAnimation(rotate, forKey: "transform.rotation.x")
CATransaction.commit()
}
UIView.animateWithDuration(0.25,
delay: 0,
usingSpringWithDamping: 1,
initialSpringVelocity: 0,
options: .CurveEaseIn,
animations: {
let radians = CGFloat(M_PI) * 0 / 180 // angle was set to -45 degrees
var transform = CATransform3DIdentity
transform.m34 = -1.0 / 500.0
transform = CATransform3DRotate(transform, radians, 1, 0, 0)
layer?.transform = transform
}, completion: { [weak self] finished in
self.removeFromSuperview()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment