タッチイベントを傍受できるように私のアプリケーションにUITableView
をサブクラス化しました。私はこれを使用して、3Dビュージェスチャーをビュー全体(テーブルビューの上を含む)に提供できるようにしています。3Dタッチ力ジェスチャーは、タッチ終了時にセルタップを有効にします。
これは素晴らしいですが、問題は、セルの1つで3Dタッチを使用してから指を離すとセルタップが有効になることです。
力が加えられていない場合は、セルタップを有効にする必要があります。私は、あなたが圧力をかけていくにつれて、徐々に画面全体にイメージをフェードアウトしていると説明しておきます。ここで
は私のサブクラスです:
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
})
}
素晴らしいです。ありがとう! – user3746428