iOS开发_开启关闭侧滑手势

1、前言

  • 在部分页面需要禁止掉手势返回功能,使用父类继承的特性,快速设置开启关闭手势返回功能。

2、头文件

@interface Update_Center_Controller : Basic_Controller 

/** 开启关闭侧滑手势,  默认 YES开启 */
@property(nonatomic, assign) BOOL pop_gesture;

@end

3、.m文件

@interface Update_Center_Controller () 

/** 开启关闭侧滑手势专用 */
@property(nonatomic, assign) BOOL gesture_flag;

@end

@implementation Update_Center_Controller

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.pop_gesture = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    if (!self.pop_gesture) {
        self.gesture_flag = NO;
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
        }
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

    if (!self.pop_gesture) {
        // 在其他离开改页面的方法同样加上下面两句代码
        self.gesture_flag = YES;
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
            self.navigationController.interactivePopGestureRecognizer.delegate = nil;
        }
    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (!self.pop_gesture) {
        // YES:允许右滑返回  NO:禁止右滑返回
        return self.gesture_flag;
    }
    else {
        return YES;
    }
}

@end
上一篇:P2216 [HAOI2007]理想的正方形


下一篇:集合的应用