关于ios7 UINavigationController.interactivePopGestureRecognizer手势集成

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

spa

若是自定义过navbar的leftbarbutton 或者backbarbutton 原生interactivePopGestureRecognizer默认是关闭的。
随着手机屏幕愈来愈大,侧滑现在已成主流。所以知足自定义的返回键的时候知足侧滑是必不可少的。

继承

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

- (void)viewDidLoadio

{class

    __weak NavigationController *weakSelf = self;select

 

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

    {im

        

        self.interactivePopGestureRecognizer.delegate = (id)weakSelf;animate

        

        self.delegate = (id)weakSelf;view

    }

}

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中不停的跳转  简直让你抓毛。所以并不推荐,  若是有哪位大大解决了还请吱一声~

相关文章
相关标签/搜索