Last active
August 29, 2015 14:22
-
-
Save mortenjust/961a9f5d27dea1ae3905 to your computer and use it in GitHub Desktop.
One-line Facebook POP animation initializer
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
class MJPOPSpring: POPSpringAnimation { | |
init(view:NSView, | |
propertyName : String? = nil, | |
toValue _toValue : AnyObject? = nil, | |
repeatForever _repeatForever:Bool? = nil, | |
repeatCount _repeatCount: Int? = nil, | |
springBounciness _springBounciness: CGFloat? = nil, | |
springSpeed _springSpeed : CGFloat? = nil, | |
dynamicsTension _dynamicsTension: CGFloat? = nil, | |
dynamicsFriction _dynamicsFriction: CGFloat? = nil, | |
dynamicsMass _dynamicsMass: CGFloat? = nil, | |
animationName : String = "animation", | |
runNow : Bool = true | |
) { | |
super.init() | |
if propertyName != nil { | |
self.property = POPAnimatableProperty.propertyWithName(propertyName) as! POPAnimatableProperty | |
} | |
self.toValue = _toValue != nil ? _toValue! : self.toValue | |
self.repeatCount = _repeatCount != nil ? _repeatCount! : self.repeatCount | |
self.repeatForever = _repeatForever != nil ? _repeatForever! : self.repeatForever | |
self.springBounciness = _springBounciness != nil ? _springBounciness! : self.springBounciness | |
self.springSpeed = _springSpeed != nil ? _springSpeed! : self.springSpeed | |
self.dynamicsTension = _dynamicsTension != nil ? _dynamicsTension! : self.dynamicsTension | |
self.dynamicsFriction = _dynamicsFriction != nil ? _dynamicsFriction! : self.dynamicsFriction | |
self.dynamicsMass = _dynamicsMass != nil ? _dynamicsMass! : self.dynamicsMass | |
if !view.wantsLayer { view.wantsLayer = true } | |
if runNow { | |
view.layer?.pop_addAnimation(self, forKey: animationName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Facebook POP has some great dynamics, but a single animation for a single property quickly takes up 5-6 lines of code. Here's an early pass at doing it in one line.