Created
February 19, 2018 12:59
-
-
Save vialyx/724280557b76a486ee6bef3013240443 to your computer and use it in GitHub Desktop.
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
// MARK: - UIViewControllerTransitioningDelegate | |
extension PaymentInformationRouter: UIViewControllerTransitioningDelegate { | |
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { | |
return HalfSizePresentationController(presentedViewController: presented, presenting: presenting) | |
} | |
} | |
class HalfSizePresentationController: UIPresentationController { | |
fileprivate var dimmingView: UIView! | |
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) { | |
super.init(presentedViewController: presentedViewController, presenting: presentingViewController) | |
setupDimmingView() | |
} | |
override var frameOfPresentedViewInContainerView: CGRect { | |
let height: CGFloat = 391 | |
let y = containerView!.frame.height - height | |
return CGRect(x: 0, y: y, width: containerView!.frame.width, height: height) | |
} | |
override func presentationTransitionWillBegin() { | |
super.presentationTransitionWillBegin() | |
containerView?.insertSubview(dimmingView, at: 0) | |
NSLayoutConstraint.activate( | |
NSLayoutConstraint.constraints(withVisualFormat: "V:|[dimmingView]|", | |
options: [], metrics: nil, views: ["dimmingView": dimmingView])) | |
NSLayoutConstraint.activate( | |
NSLayoutConstraint.constraints(withVisualFormat: "H:|[dimmingView]|", | |
options: [], metrics: nil, views: ["dimmingView": dimmingView])) | |
guard let coordinator = presentedViewController.transitionCoordinator else { | |
dimmingView.alpha = 1.0 | |
return | |
} | |
coordinator.animate(alongsideTransition: { _ in | |
self.dimmingView.alpha = 1.0 | |
}) | |
} | |
override func dismissalTransitionWillBegin() { | |
super.dismissalTransitionWillBegin() | |
guard let coordinator = presentedViewController.transitionCoordinator else { | |
dimmingView.alpha = 0.0 | |
return | |
} | |
coordinator.animate(alongsideTransition: { _ in | |
self.dimmingView.alpha = 0.0 | |
}) | |
} | |
} | |
// MARK: - Dim View | |
extension HalfSizePresentationController { | |
func setupDimmingView() { | |
dimmingView = UIView() | |
dimmingView.translatesAutoresizingMaskIntoConstraints = false | |
dimmingView.backgroundColor = UIColor.black.withAlphaComponent(0.5) | |
dimmingView.alpha = 0.0 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment