• interactivePopGestureRecognizer 遇到的问题


    界面卡死的问题

    这个问题查好了好几个晚上。表现是在root view controller乱滑时,容易卡死,进入后台一下再回来又会正常。

    做了各种尝试,排查了动画、内存和基础组件等可能的原因,无果。在近乎绝望的情况下,突然灵光一现,想起自己重构代码时,删除了几行关于导航代理的代码。

    - (void)navigationController:(UINavigationController *)navigationController
           didShowViewController:(UIViewController *)viewController
                        animated:(BOOL)animated
    {
       if (viewController == navigationController.viewControllers[0])
       {
           navigationController.interactivePopGestureRecognizer.enabled = NO;
       }else {
           navigationController.interactivePopGestureRecognizer.enabled = YES;
       }
    }

    显示root view controller时,关闭掉interactivePopGestureRecognizer这个手势。

    按钮点击无反应问题

    为了提高灵活性,来往支持view controller关闭右滑手势。为了提高性能,我用gestureRecognizerShouldBegin替换了shouldReceiveTouch。结果引入了一个我意想不到的bug。

    点击发语音消息的按钮,反映迟钝。经过无数种尝试,我发现了一些规律,按钮如果在底下的时候,左半边点击响应迟钝,右半边却很灵敏。但是在别的地方一直都会很灵敏。我重点排查了view controller和输入框上别的手势,清空所有的手势依旧如此。

    很难想象这是导航栏的手势导致的。触点在输入框不灵敏的区域时,如果能在shouldReceiveTouch快速返回NO的话,点击就非常灵敏了。

    @interface NavigationController : UINavigationController <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
    
    @end
    
    @implementation NavigationController
    
    - (id)initWithRootViewController:(UIViewController *)rootViewController
    {
        self = [super initWithRootViewController:rootViewController];
    
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.interactivePopGestureRecognizer.delegate = self;
    }
    
    #pragma mark - UIGestureRecognizerDelegate
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
           shouldReceiveTouch:(UITouch *)touch
    {
        //如果在红色方框内有长按手势,这里需要快速返回NO,要不然反映会很迟钝。
        return YES;
    }
    
    @end

    这种情况下点击按钮毫无压力,非常灵敏。


    Snip20150402_52

    这种情况下,按住红色方框区域,按钮会迟迟收不到touchesBegan,按钮不会进入highlighted状态。

  • 相关阅读:
    Java类、实例初始化的顺序
    Java中堆栈的区别
    int与Integer的区别(基本类型与复杂类型的对比)转
    JS中函数执行顺序的问题?
    springMVC --@RequestParam注解(后台控制器获取参数)
    如何安装request库
    流程图
    认识broken pipe
    postman动态使用url
    自定义一个List排序规则,然后对另一个List按照该规则排序
  • 原文地址:https://www.cnblogs.com/LiuYisiTony/p/6728457.html
Copyright © 2020-2023  润新知