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下载

  • 相关阅读:
    MyEclipe 配置 ivy 插件
    PHP 向 MySql 中数据修改操作时,只对数字操作有效,非数字操作无效,怎么办?
    Hadoop 中 Eclipse 的配置
    Hadoop 配置好hive,第一次在conf能进入,第二次就不行了,怎么办?
    7系列FPGA远程更新方案-QuickBoot(转)
    Serial interface (RS-232)
    Linux下安装微信(转)
    《图解HTTP》读书笔记(转)
    《图解TCP/IP》读书笔记(转)
    7 Serial Configuration 理解(三)
  • 原文地址:https://www.cnblogs.com/wangqw/p/5656717.html
Copyright © 2011-2022 走看看