Skip to content

Instantly share code, notes, and snippets.

@spotlessicode
Last active September 20, 2016 11:21
Show Gist options
  • Select an option

  • Save spotlessicode/3f7aedd9d37ea4d1cedcaea010c5b4cb to your computer and use it in GitHub Desktop.

Select an option

Save spotlessicode/3f7aedd9d37ea4d1cedcaea010c5b4cb to your computer and use it in GitHub Desktop.
override func perform() {
//set the ViewControllers for the animation
let sourceView = self.source.view as UIView!
let destinationView = self.destination.view as UIView!
let window = UIApplication.shared.delegate?.window!
//set the destination View center
destinationView?.center = CGPoint(x: (sourceView?.center.x)!, y: (sourceView?.center.y)! - (destinationView?.center.y)!)
// the Views must be in the Window hierarchy, so insert as a subview the destionation above the source
window?.insertSubview(destinationView!, aboveSubview: sourceView!)
//create UIAnimation- change the views's position when present it
UIView.animate(withDuration: 0.4,
animations: {
destinationView?.center = CGPoint(x: (sourceView?.center.x)!, y: (sourceView?.center.y)!)
sourceView?.center = CGPoint(x: (sourceView?.center.x)!, y: 0 + 2 * (destinationView?.center.y)!)
}, completion: {
(value: Bool) in
elf.source.navigationController?.pushViewController(self.destination, animated: false)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment