Skip to content

Instantly share code, notes, and snippets.

@dropocol
Forked from Daemon-Devarshi/Pop.swift
Created April 22, 2017 05:58
Show Gist options
  • Select an option

  • Save dropocol/f095f7665d76433b13d32df9d3e66808 to your computer and use it in GitHub Desktop.

Select an option

Save dropocol/f095f7665d76433b13d32df9d3e66808 to your computer and use it in GitHub Desktop.
Push animation using custom segue
protocol Pop {
func moveBackToParentViewController(currentViewController: UIViewController)
}
extension Pop {
func moveBackToParentViewController(currentViewController: UIViewController) {
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionMoveIn
transition.subtype = kCATransitionFromLeft
currentViewController.view.window!.layer.add(transition, forKey: kCATransition)
currentViewController.dismiss(animated: true, completion: nil)
}
}
import UIKit
class Push: UIStoryboardSegue {
override func perform() {
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
source.view.window!.layer.add(transition, forKey: kCATransition)
source.present(destination, animated: false, completion: nil)
}
}
class PushedViewController: UIViewController, Pop {
@IBAction func backAction(_ sender: AnyObject) {
moveBackToParentViewController(currentViewController: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment