Last active
October 15, 2018 10:12
-
-
Save yashthaker7/eb7074b003d0a9718f8c0e65edd7dc32 to your computer and use it in GitHub Desktop.
Custom transition using segue
This file contains hidden or 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
// | |
// SwipeUpDownTransition.swift | |
// CustomTransition | |
// | |
// Created by Yash Thaker on 18/04/18. | |
// Copyright © 2018 YashThaker. All rights reserved. | |
// | |
import UIKit | |
// MARK:- First Swipe Up | |
class FirstSwipeUpSegue: UIStoryboardSegue { | |
override func perform() { | |
swipeUp() | |
} | |
func swipeUp() { | |
let fromViewController = self.source | |
let toViewController = self.destination | |
let containerView = fromViewController.view.superview | |
guard let window = UIApplication.shared.keyWindow else { return } | |
let originalyPos = window.frame.origin.y | |
let height = window.frame.height | |
toViewController.view.frame.origin.y = height | |
containerView?.addSubview(toViewController.view) | |
UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseInOut, animations: { | |
fromViewController.view.frame.origin.y = -height | |
toViewController.view.frame.origin.y = originalyPos | |
}) { (_) in | |
fromViewController.present(toViewController, animated: false, completion: nil) | |
} | |
} | |
} | |
// MARK:- Second Swipe Down | |
class SecondSwipeDownSegue: UIStoryboardSegue { | |
override func perform() { | |
swipeDown() | |
} | |
func swipeDown() { | |
let fromViewController = self.source | |
let toViewController = self.destination | |
let containerView = fromViewController.view.superview | |
guard let window = UIApplication.shared.keyWindow else { return } | |
let originalyPos = window.frame.origin.y | |
let height = window.frame.height | |
toViewController.view.frame.origin.y = -height | |
containerView?.addSubview(toViewController.view) | |
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: { | |
fromViewController.view.frame.origin.y = +height | |
toViewController.view.frame.origin.y = originalyPos | |
}) { (_) in | |
fromViewController.dismiss(animated: false, completion: nil) | |
} | |
} | |
} | |
// MARK:- First Swipe Down | |
class FirstSwipeDownSegue: UIStoryboardSegue { | |
override func perform() { | |
swipeDown() | |
} | |
func swipeDown() { | |
let fromViewController = self.source | |
let toViewController = self.destination | |
let containerView = fromViewController.view.superview | |
guard let window = UIApplication.shared.keyWindow else { return } | |
let originalyPos = window.frame.origin.y | |
let height = window.frame.height | |
toViewController.view.frame.origin.y = -height | |
containerView?.addSubview(toViewController.view) | |
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: { | |
toViewController.view.frame.origin.y = originalyPos | |
}) { (_) in | |
fromViewController.present(toViewController, animated: false, completion: nil) | |
} | |
} | |
} | |
// MARK:- Second Swipe Up | |
class SecondSwipeUpSegue: UIStoryboardSegue { | |
override func perform() { | |
swipeUp() | |
} | |
func swipeUp() { | |
let fromViewController = self.source | |
let toViewController = self.destination | |
let containerView = fromViewController.view.superview | |
guard let window = UIApplication.shared.keyWindow else { return } | |
let height = window.frame.height | |
containerView?.insertSubview(toViewController.view, at: 0) | |
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: { | |
fromViewController.view.frame.origin.y = -height | |
}) { (_) in | |
fromViewController.dismiss(animated: false, completion: nil) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment