弹出视图控制器使用屏幕边缘平移手势识别器不跟随拇指 [英] Pop view controller using Screen edge pan gesture recogniser not following the thumb

查看:193
本文介绍了弹出视图控制器使用屏幕边缘平移手势识别器不跟随拇指的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我添加了自定义栏导航栏按钮项,我就失去了使用默认功能返回的能力。

As soon as I've added custom bar navigation bar button item I've lost the ability to use the default function to go back. I'd like to have the ability to use "swipe from edge" to go back.

我已经添加了边缘平移手势识别器并将其连接到@IBAction,但是,一旦识别到平移手势,关闭动作就会完全发生。

I've added the Edge Pan Gesture Recogniser and connected it to @IBAction, but the dismissing action happens completely as soon as the pan gesture is recognised.

不是慢慢地跟随我的拇指(如在其他应用程序中看到的),当前视图移出预定义动画。

Instead of slowly following my thumb (as seen in other apps), the current view moves out with predefined animation.

如何使用Edge Pan Gesture Recogniser在大拇指后制作动画?

How to make the animation following my thumb using Edge Pan Gesture Recogniser?

@IBAction func edgeSwipe(sender: AnyObject) {
    navigationController?.popViewControllerAnimated(true)
}

推荐答案

没有需要添加边缘平移手势识别器。按照@ beyowulf的建议,我已经能够实现滑动回去的功能,其行为与默认系统实现相同的方式 - 视图边缘跟随我的拇指,当我刷它去关闭它。

There's no need to add Edge Pan Gesture Recogniser. Following @beyowulf's suggestions I've been able to implement the swipe to go back feature that behaves the same way as the default system implementation does - the views edge follows my thumb as I swipe it to dismiss it.

所以我从故事板中删除了 ScreenEdge Pan Gesture Recogniser ,并删除了相关的 @IBAction

So I've removed the ScreenEdge Pan Gesture Recogniser from the storyboard and also removed the related @IBAction.

我已经使我的第一个视图控制器成为 interactivePopGestureRecognizer 的委托。这里是代码:

I've made my first view controller to be the delegate for interactivePopGestureRecognizer. Here's the code:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.interactivePopGestureRecognizer?.delegate = self
    }
}

extension ViewController: UIGestureRecognizerDelegate {

    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return navigationController?.viewControllers.count > 1 ? true : false
    }
}

这篇关于弹出视图控制器使用屏幕边缘平移手势识别器不跟随拇指的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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