我已经在我的应用程序中设置了UITableView
子类,以便我可以拦截触摸事件。我正在使用它来允许我在整个视图上提供3D Touch手势(包括在表格视图的顶部)。
这很有效,但问题是在其中一个单元格上使用3D Touch然后释放手指会激活单元格。
如果没有施加力,我只需要激活细胞水龙头。我应该解释一下,当你施加压力时,我会在整个屏幕上逐渐淡化图像。
这是我的子类:
protocol PassTouchesTableViewDelegate {
func touchMoved(touches: Set<UITouch>)
func touchEnded(touches: Set<UITouch>)
}
class PassTouchesTableView: UITableView {
var delegatePass: PassTouchesTableViewDelegate?
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesMoved(touches, withEvent: event)
self.delegatePass?.touchMoved(touches)
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
self.delegatePass?.touchEnded(touches)
}
}
以下是当触摸结束并移动时我从视图控制器调用的方法:
internal func touchMoved(touches: Set<UITouch>) {
let touch = touches.first
self.pressureImageView.alpha = (touch!.force / 2) - 1.0
}
internal func touchEnded(touches: Set<UITouch>) {
UIView.animateWithDuration(0.2, animations: {
self.pressureImageView.alpha = 0.0
})
}
答案 0 :(得分:1)
你可以创建一个名为isForceTouch的布尔值,在touchesBegan中设置为false,然后一旦检测到强制触摸,将其设置为true。然后在didSelectRowAtIndexPath中,如果isForceTouch为true,则返回false。它可能需要调整,但这应该工作。