UIViewController+Presentation.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // UIViewController+Presentation.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/1/7.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. fileprivate struct AssociatedKeys {
  10. fileprivate static var controllerHeightKey :String = "controllerHeight"
  11. }
  12. extension UIViewController:UIViewControllerTransitioningDelegate{
  13. var controllerHeight : CGFloat?{
  14. set{
  15. objc_setAssociatedObject(self, &AssociatedKeys.controllerHeightKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
  16. }
  17. get{
  18. return objc_getAssociatedObject(self, &AssociatedKeys.controllerHeightKey) as? CGFloat
  19. }
  20. }
  21. func modal(_ vc:UIViewController,controllerHeight:CGFloat) {
  22. vc.modalPresentationStyle = .custom
  23. vc.controllerHeight = controllerHeight
  24. vc.transitioningDelegate = self
  25. self.present(vc, animated: true, completion: nil)
  26. }
  27. public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
  28. return IHPresentBottom(presentedViewController: presented, presenting: presenting)
  29. }
  30. }