zoukankan      html  css  js  c++  java
  • 关于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中不停的跳转  简直让你抓毛。因此并不推荐,  如果有哪位大大解决了还请吱一声~

  • 相关阅读:
    Understand Rails Authenticity Token
    正则表达式:数值及数值型字符串三位一组格式化
    ceph主要数据结构解析2-Rados.h文件
    遍历聚合对象中的元素——迭代器模式(三)
    ceph主要数据结构解析3-Ceph_fs.h文件
    linux crontab 定时命令
    mysql数据类型详解
    遍历聚合对象中的元素——迭代器模式(四)
    Eclipse自动插件依赖的一种配置解决方式
    php缓存小技巧
  • 原文地址:https://www.cnblogs.com/seth-chen/p/5179725.html
Copyright © 2011-2022 走看看