Last active
August 10, 2016 14:21
-
-
Save harryworld/8524cc61bcc192beec92a4affafa5cc5 to your computer and use it in GitHub Desktop.
Comparing iOS vs macOS animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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