Instantly share code, notes, and snippets.
tylerlantern
/ BHMenuTransitionAnimatorPart1.swift
Last active
December 24, 2018 15:20
This file contains 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
class BHMenuTransitionAnimator: NSObject , UIViewControllerAnimatedTransitioning { | |
var fromViewController : UIViewController! | |
init(fromViewController vc : UIViewController ) { | |
super.init() | |
self.fromViewController = vc | |
} | |
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { |
tylerlantern
/ BHMenuTransitionAnimatorPart2.swift
Created
December 24, 2018 15:21
This file contains 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
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { | |
let containerView = transitionContext.containerView | |
transitionContext.viewController(forKey: .from) | |
let fromVc = transitionContext.viewController(forKey: .from)! | |
let toVc = transitionContext.viewController(forKey: .to)! | |
let isPresenting = self.fromViewController == fromVc ? true : false | |
if isPresenting{ | |
let targetWidth = fromVc.view.frame.width * 0.85 | |
toVc.view.frame = CGRect(x: targetWidth * -1, y: 0, width: targetWidth, height: fromVc.view.frame.height) | |
containerView.addSubview(toVc.view) |
tylerlantern
/ BHMenuTransitionManagerPart1.swift
Created
December 24, 2018 15:22
This file contains 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
class BHMenuTransitionManager: NSObject { | |
var transitionAnimator : BHMenuTransitionAnimator! | |
init(instance : BHMenuTransitionManagerDelegate,fromViewController vc: UIViewController ) { | |
super.init() | |
transitionAnimator = BHMenuTransitionAnimator(fromViewController: vc) | |
} | |
} |
tylerlantern
/ BHMenuTransitionManagerExtension.swift
Created
December 24, 2018 15:23
This file contains 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
extension BHMenuTransitionManager : UIViewControllerTransitioningDelegate { | |
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
return transitionAnimator | |
} | |
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
return transitionAnimator | |
} | |
tylerlantern
/ FirstViewController.swift
Created
December 24, 2018 15:29
This file contains 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
class FirstViewController: UIViewController { | |
lazy var transitionManager = BHMenuTransitionManager(instance: self, fromViewController: self.navigationController!) | |
@IBAction func action_openSideMenu(_ sender: Any) { | |
self.performSegue(withIdentifier: "segueMenu", sender: nil) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} |
tylerlantern
/ MenuViewController.swift
Created
December 24, 2018 15:32
This file contains 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
class MenuViewController : UIViewController { | |
@IBAction func action_dismiss(_ sender: Any) { | |
self.dismiss(animated: true, completion: nil) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
tylerlantern
/ BHMenuPresentationInit.swift
Last active
December 27, 2018 05:09
This file contains 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
public class BHMenuPresentation: UIPresentationController { | |
var bhDelegate : BHMenuPresentationDelegate? | |
public var dimmingView: UIView! | |
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) { | |
super.init(presentedViewController: presentedViewController, presenting: presentingViewController) | |
setupDimmingView() | |
} | |
tylerlantern
/ BHMenuPresentationTransition.swift
Created
December 27, 2018 05:29
This file contains 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
override public func presentationTransitionWillBegin() { | |
super.presentationTransitionWillBegin() | |
dimmingView.frame = presentingViewController.view.bounds | |
containerView?.addSubview(dimmingView) | |
guard let coordinator = presentedViewController.transitionCoordinator else { | |
return | |
} | |
coordinator.animate(alongsideTransition: { (context) in | |
self.dimmingView.alpha = 0.5 | |
}, completion: nil) |
tylerlantern
/ BHMenuTransitionManagerPresentationController.swift
Last active
December 27, 2018 06:00
This file contains 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
extension BHMenuTransitionManager : UIViewControllerTransitioningDelegate { | |
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { | |
presentationAnimator = BHMenuPresentation(presentedViewController: presented, presenting: presenting) | |
return presentationAnimator | |
} | |
} |
tylerlantern
/ BHMenuInteraction.swift
Created
December 27, 2018 08:46
This file contains 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
class BHMenuInteraction: UIPercentDrivenInteractiveTransition { | |
var transitionInProgress = false | |
var shouldCompleteTransition = false | |
var const : CGFloat = 0 | |
var presentedViewController : UIViewController! | |
func attachViewController(presentedViewController vc : UIViewController) { | |
presentedViewController = vc | |
} | |
func setUpGestureOnView(view : UIView?){ | |
guard let view = view else {return} |
OlderNewer