HWPanModalPresentationDelegate.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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) HWPanModalInteractiveAnimator *interactiveDismissalAnimator;
  13. @end
  14. @implementation HWPanModalPresentationDelegate
  15. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
  16. return [[HWPanModalPresentationAnimator alloc] initWithTransitionStyle:TransitionStylePresentation interactiveMode:PanModalInteractiveModeNone];
  17. }
  18. - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
  19. return [[HWPanModalPresentationAnimator alloc] initWithTransitionStyle:TransitionStyleDismissal interactiveMode:self.interactiveMode];
  20. }
  21. - (nullable id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator {
  22. if (self.interactive) {
  23. return self.interactiveDismissalAnimator;
  24. }
  25. return nil;
  26. }
  27. - (nullable UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(nullable UIViewController *)presenting sourceViewController:(UIViewController *)source {
  28. UIPresentationController *controller = [[HWPanModalPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
  29. controller.delegate = self;
  30. return controller;
  31. }
  32. #pragma mark - UIAdaptivePresentationControllerDelegate
  33. - (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
  34. return UIModalPresentationNone;
  35. }
  36. #pragma mark - Getter
  37. - (HWPanModalInteractiveAnimator *)interactiveDismissalAnimator {
  38. if (!_interactiveDismissalAnimator) {
  39. _interactiveDismissalAnimator = [[HWPanModalInteractiveAnimator alloc] init];
  40. }
  41. return _interactiveDismissalAnimator;
  42. }
  43. #ifdef DEBUG
  44. - (void)dealloc {
  45. NSLog(@"%s", __PRETTY_FUNCTION__);
  46. }
  47. #endif
  48. @end