説明なし

SGPagingViewPopGestureVC.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // SGPagingViewPopGestureVC.m
  3. // SGPagingViewExample
  4. //
  5. // Created by kingsic on 2018/9/1.
  6. // Copyright © 2018年 kingsic. All rights reserved.
  7. //
  8. #import "SGPagingViewPopGestureVC.h"
  9. @interface SGPagingViewPopGestureVC () <UIGestureRecognizerDelegate> {
  10. id<UIGestureRecognizerDelegate> _delegate;
  11. }
  12. @end
  13. @implementation SGPagingViewPopGestureVC
  14. - (void)viewWillAppear:(BOOL)animated {
  15. [super viewWillAppear:animated];
  16. if (self.navigationController.viewControllers.count > 1) {
  17. // 记录系统返回手势的代理
  18. _delegate = self.navigationController.interactivePopGestureRecognizer.delegate;
  19. // 设置系统返回手势的代理为当前控制器
  20. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  21. }
  22. }
  23. - (void)viewWillDisappear:(BOOL)animated {
  24. [super viewWillDisappear:animated];
  25. // 设置系统返回手势的代理为我们刚进入控制器的时候记录的系统的返回手势代理
  26. self.navigationController.interactivePopGestureRecognizer.delegate = _delegate;
  27. }
  28. #pragma mark - - UIGestureRecognizerDelegate
  29. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  30. return self.navigationController.childViewControllers.count > 1;
  31. }
  32. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  33. return self.navigationController.viewControllers.count > 1;
  34. }
  35. @end