HWPanModalPresentationDelegate.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // HWPanModalPresentationDelegate.m
  3. // HWPanModal
  4. //
  5. // Created by heath wang on 2019/4/29.
  6. //
  7. #import "HWPanModalPresentationDelegate.h"
  8. #import "HWPanModalPresentationAnimator.h"
  9. #import "HWPanModalPresentationController.h"
  10. #import "HWPanModalInteractiveAnimator.h"
  11. @interface HWPanModalPresentationDelegate ()
  12. @property (nonatomic, strong) HWPanModalPresentationAnimator *presentationAnimator;
  13. @property (nonatomic, strong) HWPanModalPresentationAnimator *dismissalAnimator;
  14. @property (nonatomic, strong) HWPanModalInteractiveAnimator *interactiveDismissalAnimator;
  15. @end
  16. @implementation HWPanModalPresentationDelegate
  17. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
  18. return self.presentationAnimator;
  19. }
  20. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
  21. return self.dismissalAnimator;
  22. }
  23. - (nullable id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator {
  24. if (self.interactive) {
  25. return self.interactiveDismissalAnimator;
  26. }
  27. return nil;
  28. }
  29. - (nullable UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(nullable UIViewController *)presenting sourceViewController:(UIViewController *)source {
  30. UIPresentationController *controller = [[HWPanModalPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
  31. controller.delegate = self;
  32. return controller;
  33. }
  34. #pragma mark - UIAdaptivePresentationControllerDelegate
  35. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
  36. return UIModalPresentationNone;
  37. }
  38. #pragma mark - Getter
  39. - (HWPanModalPresentationAnimator *)presentationAnimator {
  40. if (!_presentationAnimator) {
  41. _presentationAnimator = [[HWPanModalPresentationAnimator alloc] initWithTransitionStyle:TransitionStylePresentation];
  42. }
  43. return _presentationAnimator;
  44. }
  45. - (HWPanModalPresentationAnimator *)dismissalAnimator {
  46. if (!_dismissalAnimator) {
  47. _dismissalAnimator = [[HWPanModalPresentationAnimator alloc] initWithTransitionStyle:TransitionStyleDismissal];
  48. }
  49. return _dismissalAnimator;
  50. }
  51. - (HWPanModalInteractiveAnimator *)interactiveDismissalAnimator {
  52. if (!_interactiveDismissalAnimator) {
  53. _interactiveDismissalAnimator = [[HWPanModalInteractiveAnimator alloc] init];
  54. }
  55. return _interactiveDismissalAnimator;
  56. }
  57. @end