Skip to content

Instantly share code, notes, and snippets.

@Wassmd
Created January 14, 2020 15:29
Show Gist options
  • Save Wassmd/0713b0c1c1eb693c9250dfbf7caa2de0 to your computer and use it in GitHub Desktop.
Save Wassmd/0713b0c1c1eb693c9250dfbf7caa2de0 to your computer and use it in GitHub Desktop.
//
// ViewController.swift
// ChainAnimation
//
// Created by Mohammed Wasimuddin on 14.01.20.
// Copyright © 2020 Wasim. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var bodyLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(showChainAninamation)))
}
@objc func showChainAninamation() {
print("inside chain reaction")
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseOut, animations: {
self.titleLabel.transform = CGAffineTransform(translationX: -30, y: 0)
}) { (_) in
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.titleLabel.alpha = 0
self.titleLabel.transform = CGAffineTransform(translationX: 0, y: -200)
})
}
UIView.animate(withDuration: 0.5, delay: 0.5, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseOut, animations: {
self.bodyLabel.transform = CGAffineTransform(translationX: -30, y: 0)
}) { (_) in
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.bodyLabel.alpha = 0
self.bodyLabel.transform = CGAffineTransform(translationX: 0, y: -200)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment