Last active
January 1, 2019 16:33
-
-
Save myrickchow32/ad794c76361ab296b5b2a0e0ef184b53 to your computer and use it in GitHub Desktop.
This file contains 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
// Definition of UILabels | |
@IBOutlet var easeInLabel: UILabel! | |
@IBOutlet var easeOutLabel: UILabel! | |
@IBOutlet var easeInOutLabel: UILabel! | |
@IBOutlet var linearLabel: UILabel! | |
@IBOutlet var transitionFlipFromLeftLabel: UILabel! | |
@IBOutlet var transitionFlipFromRightLabel: UILabel! | |
@IBOutlet var transitionCurlUpLabel: UILabel! | |
@IBOutlet var transitionCurlDownLabel: UILabel! | |
@IBOutlet var transitionCrossDissolveLabel: UILabel! | |
@IBOutlet var transitionFlipFromTopLabel: UILabel! | |
@IBOutlet var transitionFlipFromBottomLabel: UILabel! | |
// All animations are done with the same length of duration --- 1.0 second | |
let durationOfAnimationInSecond = 1.0 | |
@IBAction func startAnimationButtonAction(_ sender: UIButton) { | |
// Curve animation | |
curveAnimation(view: easeInLabel, animationOptions: .curveEaseIn, isReset: isAnimated) | |
curveAnimation(view: easeOutLabel, animationOptions: .curveEaseOut, isReset: isAnimated) | |
curveAnimation(view: easeInOutLabel, animationOptions: .curveEaseInOut, isReset: isAnimated) | |
curveAnimation(view: linearLabel, animationOptions: .curveLinear, isReset: isAnimated) | |
// Transition animation | |
transitionAnimation(view: transitionFlipFromLeftLabel, animationOptions: .transitionFlipFromLeft, isReset: isAnimated) | |
transitionAnimation(view: transitionFlipFromRightLabel, animationOptions: .transitionFlipFromRight, isReset: isAnimated) | |
transitionAnimation(view: transitionCurlUpLabel, animationOptions: .transitionCurlUp, isReset: isAnimated) | |
transitionAnimation(view: transitionCurlDownLabel, animationOptions: .transitionCurlDown, isReset: isAnimated) | |
transitionAnimation(view: transitionCrossDissolveLabel, animationOptions: .transitionCrossDissolve, isReset: isAnimated) | |
transitionAnimation(view: transitionFlipFromTopLabel, animationOptions: .transitionFlipFromTop, isReset: isAnimated) | |
transitionAnimation(view: transitionFlipFromBottomLabel, animationOptions: .transitionFlipFromBottom, isReset: isAnimated) | |
isAnimated.toggle() | |
} | |
func curveAnimation(view: UIView, animationOptions: UIView.AnimationOptions, isReset: Bool) { | |
let defaultXMovement: CGFloat = 240 | |
UIView.animate(withDuration: durationOfAnimationInSecond, delay: 0, options: animationOptions, animations: { | |
view.transform = isReset ? .identity : CGAffineTransform.identity.translatedBy(x: defaultXMovement, y: 0) | |
}, completion: nil) | |
} | |
func transitionAnimation(view: UIView, animationOptions: UIView.AnimationOptions, isReset: Bool) { | |
UIView.transition(with: view, duration: durationOfAnimationInSecond, options: animationOptions, animations: { | |
view.backgroundColor = UIColor.init(named: isReset ? "darkGreen" : "darkRed") | |
}, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment