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