• iOS 如何在整个屏幕中都能实现滑动返回的效果


     1 - (void)setupGetsInNav
     2 {
     3     UIGestureRecognizer *gesture = self.interactivePopGestureRecognizer;
     4     gesture.enabled = NO;
     5     UIView *gestureView = gesture.view;
     6     
     7     UIPanGestureRecognizer *popRecognizer = [[UIPanGestureRecognizer alloc] init];
     8     popRecognizer.delegate = self;
     9     popRecognizer.maximumNumberOfTouches = 1;
    10     [gestureView addGestureRecognizer:popRecognizer];
    11     /**
    12      *  获取系统手势的target数组
    13      */
    14     NSMutableArray *_targets = [gesture valueForKey:@"_targets"];
    15     /**
    16      *  获取它的唯一对象,我们知道它是一个叫UIGestureRecognizerTarget的私有类,它有一个属性叫_target
    17      */
    18     id gestureRecognizerTarget = [_targets firstObject];
    19     /**
    20      *  获取_target:_UINavigationInteractiveTransition,它有一个方法叫handleNavigationTransition:
    21      */
    22     id navigationInteractiveTransition = [gestureRecognizerTarget valueForKey:@"_target"];
    23     /**
    24      *  通过前面的打印,我们从控制台获取出来它的方法签名。
    25      */
    26     SEL handleTransition = NSSelectorFromString(@"handleNavigationTransition:");
    27     /**
    28      *  创建一个与系统一模一样的手势,我们只把它的类改为UIPanGestureRecognizer
    29      */
    30     [popRecognizer addTarget:navigationInteractiveTransition action:handleTransition];
    31 
    32 }
    1 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    2     /**
    3      *  这里有两个条件不允许手势执行,1、当前控制器为根控制器;2、如果这个push、pop动画正在执行(私有属性)
    4      */
    5     return self.viewControllers.count != 1 && ![[self valueForKey:@"_isTransitioning"] boolValue];
    6 }

    只需要在全局的导航控制器中添加上边代码即可

  • 相关阅读:
    [LeetCode] 1103. Distribute Candies to People 分糖果
    [LeetCode] 994. Rotting Oranges 腐烂的橘子
    [LeetCode] 面试题 10.01.合并排序的数组
    [LeetCode] 207. Course Schedule 课程表
    Windows下利用virtualenvwrapper指定python版本创建虚拟环境
    Vagrant Ansible Playbook 安装一群虚拟机
    selenium grid的使用与配置
    selenium之 玩转鼠标键盘操作(ActionChains)
    Python3.7 dataclass 介绍
    简单的验证码识别
  • 原文地址:https://www.cnblogs.com/machao/p/4770762.html
Copyright © 2020-2023  润新知