关于ios7 UINavigationController.interactivePopGestureRecognizer手势集成

因为公司业务需求,结合网上的资料整理了一下。

如果自定义过navbar的leftbarbutton 或者backbarbutton 原生interactivePopGestureRecognizer默认是关闭的。
随着手机屏幕越来越大,侧滑如今已成主流。因此满足自定义的返回键的时候满足侧滑是必不可少的。

1.在navigationController  开启navigationController的interactivePopGestureRecognizer(建议自定义一个nav, 这个在哪无所谓,关键是要把当前的nav手势打开)

- (void)viewDidLoad

{

    __weak NavigationController *weakSelf = self;

 

    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)])

    {

        

        self.interactivePopGestureRecognizer.delegate = (id)weakSelf;

        

        self.delegate = (id)weakSelf;

    }

}

2.basevc中(建议自定义一个所有的vc都继承的baseVC)

- (void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:animated];

    UIViewController * rootvc = self.navigationController.viewControllers[0];

    if ([rootvc isEqual:self]) { //这里必须要把栈低的vc的interactivePopGestureRecognizer挂掉  不然会有些意想不到的bug

        self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    }else{

        self.navigationController.interactivePopGestureRecognizer.enabled = YES;

    }

}

 

补充, self.navigationController.interactivePopGestureRecognizer可以像其他手势一样添加事件,但是这是个危险的操作,

因为在你风骚的侧滑时,self的class会在两个vc中不停的跳转  简直让你抓毛。因此并不推荐,  如果有哪位大大解决了还请吱一声~

posted @ 2016-02-03 15:02  Seth-Chen  阅读(741)  评论(1编辑  收藏  举报