Skip to content

Instantly share code, notes, and snippets.

@leoiphonedev
Created September 15, 2018 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoiphonedev/f9246d32110c0aeba7c0495683195448 to your computer and use it in GitHub Desktop.
Save leoiphonedev/f9246d32110c0aeba7c0495683195448 to your computer and use it in GitHub Desktop.
Adding animation code as an extension
//
// ViewController.swift
// CATransition-Example
//
// Created by Aman Aggarwal on 29/08/18.
// Copyright © 2018 iostutorialjunction.com. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var lblCounter: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func incrementCounter(_ sender: Any) {
}
@IBAction func decrementCounter(_ sender: Any) {
}
}
extension CALayer {
func bottomAnimation(duration:CFTimeInterval) {
let animation = CATransition()
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
animation.duration = duration
animation.type = kCATransitionPush
animation.subtype = kCATransitionFromTop
self.add(animation, forKey: kCATransitionPush)
}
func topAnimation(duration:CFTimeInterval) {
let animation = CATransition()
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
animation.duration = duration
animation.type = kCATransitionPush
animation.subtype = kCATransitionFromBottom
self.add(animation, forKey: kCATransitionPush)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment