zoukankan      html  css  js  c++  java
  • UINavigationController 的一些坑

    坑一:自定义导航栏返回键 iOS7及之后版本 手势边缘右滑返回失效

    解决方案:

    -(void)viewDidLoad{
        
        [super viewDidLoad];
        
        //self 为 UINavigationController 子类
        self.interactivePopGestureRecognizer.delegate=(id)self;
        
    }

    网上千篇一律都是该答案,确实加了这句话可以手势返回了,然而却又埋下了新的坑。

    坑二:在UINavigationController的rootViewController触发手势边缘右滑,然后触发push方法界面卡死,必须重新边缘右滑后方可恢复,如下图所示

    解决方案:

    坑二的问题主要是由坑一埋下的,为何出现坑二的情况并不清楚,有知道的麻烦告知谢谢。

    -(void)viewDidLoad{
        
        [super viewDidLoad];
        
        self.interactivePopGestureRecognizer.delegate=(id)self;
        
        //实现UINavigationControllerDelegate协议
        self.delegate = self;
    }
    
    //push完成 且界面显示完成时 这个是Delegate的方法
     - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        
    if (navigationController.viewControllers.count == 1) {

          //如果是 rootViewController 禁止滑动手势
          self.interactivePopGestureRecognizer.enabled = NO;
        }
    else{
        
          //如果不是 就启用 滑动手势
          self.interactivePopGestureRecognizer.enabled = YES;
        }
    }

    坑三:在视图Push过程中,且Push尚未完成时触发了Pop,可能会导致界面卡死,不响应任何手势,点击事件

    解决方案:重写 push方法 

    - (void) pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        
        self.interactivePopGestureRecognizer.enabled = NO;
        
        [super pushViewController:viewController animated:animated];
    }

    push时禁用了,push完就要开启,否则手势就无效了。开启方法同坑二,实现UINavigationControllerDelegate 方法 

     - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    }

    swift demo下载

    oc demo下载

  • 相关阅读:
    【WIN32API&DAPI】窗口相关函数
    第十四章_安全性
    android实现gif图与文字混排
    Extjs 4.2 设置buttontext为中文
    HDU 5384 Danganronpa (AC自己主动机模板题)
    bzoj2938【Poi2000】病毒
    [Java开发之路](9)对象序列化与反序列化
    atitit.jndi的架构与原理以及资源配置and单元測试实践
    QueryError:Incorrect result size: expected 1, actual 0
    LightOJ 1070 Algebraic Problem (推导+矩阵高速幂)
  • 原文地址:https://www.cnblogs.com/wangqw/p/5656717.html
Copyright © 2011-2022 走看看