• 第十三篇、Swift_Nav自定义返回按钮后或者隐藏导航栏,Pop返回手势失效的解决方法 Pop全局返回添加的方法


    边缘的pop返回手势:

        override func viewDidLoad() {
            super.viewDidLoad()
            view.backgroundColor = UIColor.purple
            // 保留Pop手势
            navigationController?.interactivePopGestureRecognizer?.delegate = self
            navigationController?.interactivePopGestureRecognizer?.isEnabled = true
        }

    这些代码主要实在UINavigationController上添加

    Swift全屏pop返回手势:

    class CustomNavigationController: UINavigationController {
        override func viewDidLoad() {
            super.viewDidLoad()
            // 1.取出手势&view
            guard let gesture = interactivePopGestureRecognizer else { return }
            gesture.isEnabled = false
            let gestureView = gesture.view
            // 2.获取所有的target
            let target = (gesture.value(forKey: "_targets") as? [NSObject])?.first
            guard let transition = target?.value(forKey: "_target") else { return }
            let action = Selector(("handleNavigationTransition:"))
            // 3.创建新的手势
            let popGes = UIPanGestureRecognizer()
            popGes.maximumNumberOfTouches = 1
            gestureView?.addGestureRecognizer(popGes)
            popGes.addTarget(transition, action: action)
        }
        override func pushViewController(_ viewController: UIViewController, animated: Bool) {
            viewController.hidesBottomBarWhenPushed = true
            super.pushViewController(viewController, animated: animated)
        }
    }

    OC POP手势返回:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        id target = self.interactivePopGestureRecognizer.delegate;
        UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
        pan.delegate = self;
        [self.view addGestureRecognizer:pan];
        [self.interactivePopGestureRecognizer setEnabled:NO];
    }
    
    - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
        return self.childViewControllers.count == 1 ? NO : YES;
    }
  • 相关阅读:
    2016年 IT 趋势大预测!
    怎样创建合适的告警处理流程?
    如何解决 Java 安全问题?
    程序员:如何成为一个全栈的工程师?
    安全防护:你是否正在追逐一个不可能实现的目标?
    如何使用 Python 创建一个 NBA 得分图?
    如何对 Android 库进行依赖管理?
    减少 WAF 漏报的 8 种方法 !
    第69节:Java中数据库的多表操作
    第69节:Java中数据库的多表操作
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5966559.html
Copyright © 2020-2023  润新知