CTAssetsNavigationController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. MIT License (MIT)
  3. Copyright (c) 2015 bawn
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #import "CTAssetsNavigationController.h"
  21. @interface CTAssetsNavigationController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>
  22. @end
  23. @implementation CTAssetsNavigationController
  24. - (void)viewDidLoad
  25. {
  26. [super viewDidLoad];
  27. __weak CTAssetsNavigationController<UIGestureRecognizerDelegate> *weakSelf = self;
  28. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
  29. {
  30. self.interactivePopGestureRecognizer.delegate = weakSelf;
  31. self.delegate = weakSelf;
  32. }
  33. }
  34. - (void)didReceiveMemoryWarning {
  35. [super didReceiveMemoryWarning];
  36. // Dispose of any resources that can be recreated.
  37. }
  38. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
  39. {
  40. if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] && animated == YES )
  41. {
  42. self.interactivePopGestureRecognizer.enabled = NO;
  43. }
  44. [super pushViewController:viewController animated:animated];
  45. }
  46. - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
  47. {
  48. if ( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] && animated == YES )
  49. {
  50. self.interactivePopGestureRecognizer.enabled = NO;
  51. }
  52. return [super popToRootViewControllerAnimated:animated];
  53. }
  54. - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated
  55. {
  56. if( [self respondsToSelector:@selector(interactivePopGestureRecognizer)] )
  57. {
  58. self.interactivePopGestureRecognizer.enabled = NO;
  59. }
  60. return [super popToViewController:viewController animated:animated];
  61. }
  62. #pragma mark UINavigationControllerDelegate
  63. - (void)navigationController:(UINavigationController *)navigationController
  64. didShowViewController:(UIViewController *)viewController
  65. animated:(BOOL)animate
  66. {
  67. if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])
  68. {
  69. self.interactivePopGestureRecognizer.enabled = YES;
  70. }
  71. }
  72. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
  73. {
  74. if ( gestureRecognizer == self.interactivePopGestureRecognizer )
  75. {
  76. if ( self.viewControllers.count < 2 || self.visibleViewController == self.viewControllers[0] )
  77. {
  78. return NO;
  79. }
  80. }
  81. return YES;
  82. }
  83. @end