Last active
November 29, 2017 03:22
-
-
Save leilee/8685b3f95a69fcc8a9f218ad6ad171d8 to your computer and use it in GitHub Desktop.
#UIKit #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
+ (void)animateWithDuration:(NSTimeInterval)duration | |
timingFunction:(CAMediaTimingFunction*)timingFunction | |
animations:(void (^)(void))animations | |
completion:(void (^)(BOOL finished))completion | |
{ | |
[CATransaction begin]; | |
[CATransaction setAnimationDuration:duration]; | |
[CATransaction setAnimationTimingFunction:timingFunction]; | |
[UIView animateWithDuration:duration animations:animations completion:completion]; | |
[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
extension UIView { | |
static func animate(duration: TimeInterval, | |
timingFunction: CAMediaTimingFunction, | |
animations: @escaping () -> (), | |
completion: ((Bool) -> ())? = nil) { | |
CATransaction.begin() | |
CATransaction.setAnimationDuration(duration) | |
CATransaction.setAnimationTimingFunction(timingFunction) | |
animate(withDuration: duration, animations: animations, completion: completion) | |
CATransaction.commit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment