2016-04-22 74 views
1

我在我的應用程序中劃分了UITableView,這樣我就可以截取觸摸事件。我正在使用它來允許我在整個視圖(包括表格視圖頂部)上提供3D觸摸手勢。3D觸摸力量手勢激活觸摸端的單元格敲擊

這很好用,但問題是在其中一個單元格上使用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 
    }) 
} 

回答

1

您可以創建一個名爲isForceTouch布爾在touchesBegan中設置爲false,然後一旦檢測到強制觸摸,將其設置爲true。然後在didSelectRowAtIndexPath中,如果isForceTouch爲true,則返回false。它可能需要調整,但應該工作。

+0

工程很棒。謝謝! – user3746428