require(toFail)不适用于PanGestureRecognizer和PageViewController

时间:2017-07-28 22:53:38

标签: ios swift uikit uigesturerecognizer

这是我遇到的问题:

我有一个PageViewController,可以在{{>>水平的4个视图和PanGestureRecognizer上的UIView之间导航,使其在垂直<上> STRONG>。问题是UIView可能会被淘汰,但它会被卡在那里。用户只能使用PageViewController水平滑动。

目标:

能够向上和向下平移UIView并在PageViewController上左右滑动。基本上,让UIView不会卡在屏幕上。

这就是我现在所拥有的:

PanGestureRecognizer文件中有一个UIView函数,看起来像

like this:
    func handlePan(recognizer: UIPanGestureRecognizer) {
        let vel = recognizer.velocity(in: self)
        print("HANDLING PAN")
        switch recognizer.state {
        case .began:
            if vel.y < 0 && !scanIsUp {
                animator = UIViewPropertyAnimator(duration: 1, curve: .easeOut, animations: {
                    self.frame = self.frame.offsetBy(dx: 0, dy: -603)
                })
                scanIsUp = true
                isScanVisible = true
            } else if vel.y > 0 && scanIsUp {
                print("vel.y hehehe")
                animator = UIViewPropertyAnimator(duration: 1, curve: .easeOut, animations: {
                    self.frame = self.frame.offsetBy(dx: 0, dy: 603)
                })
                scanIsUp = false
                isScanVisible = false
            }
            animator?.pauseAnimation()
            print("paused?")
        case .changed:
            let translation = recognizer.translation(in: backgroundImage)
            if vel.y < 0 && scanIsUp {
                animator?.fractionComplete = translation.y / -603
            } else if vel.y > 0 && !scanIsUp {
                print("vel.y hehehe pt 2")
                animator?.fractionComplete = translation.y / 603
            }
        case .ended:
            animator?.continueAnimation(withTimingParameters: nil, durationFactor: 0)
        case .possible: break
        default: break
        }
    }

我还有一个gestureRecognizers数组来控制PageViewController。我循环遍历它们并要求它们失败,以便用户可以像这样向上和向下平移UIView

    if #available(iOS 10.0, *) {
        self.panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(PFScan.handlePan))
        self.panGestureRecognizer!.maximumNumberOfTouches = 1
        self.panGestureRecognizer!.cancelsTouchesInView = false
        self.addGestureRecognizer(self.panGestureRecognizer!)
        for recognizer in self.scrollViewGestureRecognizers {
            recognizer.require(toFail: panGestureRecognizer!)
        }
    }

最后,我在PageViewController的主视图控制器部分初始化UIView,如下所示:

func setUpScanPage(scrollViewGestureRecognizers: [UIGestureRecognizer]) {

    scanPage = PFScan(scrollViewGestureRecognizers: scrollViewGestureRecognizers)

    self.view.addSubview(scanPage)
}

有谁知道UIView被卡住的原因?我已经尝试过我所知道的一切。任何帮助都会非常感激。

非常感谢先进。干杯, 西奥

0 个答案:

没有答案