这是我遇到的问题:
我有一个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
被卡住的原因?我已经尝试过我所知道的一切。任何帮助都会非常感激。
非常感谢先进。干杯, 西奥