隐藏导航栏时如何启用滑动手势? [英] How to enable swipe gesture when navigation bar is hidden?

查看:161
本文介绍了隐藏导航栏时如何启用滑动手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图解决这个问题已经有一段时间了,并且无法弄明白。我有当前的设置:

I've been trying to solve this issue for quite some time and cant figure it out. I have the current set up:

In每个视图控制器我都隐藏了导航栏,如下所示:

In each view controller I hide the navigation bar like so:

        self.navigationController?.setNavigationBarHidden(true, animated: true)

问题是我在视图控制器上松开了导航栏隐藏的滑动手势。我需要启用动画并且无法使用:

The issue is I loose the swipe gesture on the view controllers that the navigation bar is hidden. I need to have the animation enabled and cannot use:

    self.navigationController?.navigationBar.isHidden = true
    self.navigationController?.isNavigationBarHidden = true 

任何帮助都会很棒,因为我相信很多人都跑了进入这个问题。谢谢!

Any help would be awesome as I'm sure many people has ran into this issue. Thanks!

推荐答案

以下是答案:只需继承您的NavigationController并执行以下操作。

Here is the answer: Just subclass your NavigationController and do the following.

  import UIKit

class YourUINavigationController: UINavigationController {
        override func viewDidLoad() {
            super.viewDidLoad()
            interactivePopGestureRecognizer?.delegate = self
        }
    }

    extension VaultUINavigationController: UIGestureRecognizerDelegate {
        func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
            return viewControllers.count > 1
        }
    }

这篇关于隐藏导航栏时如何启用滑动手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆