2016-01-07 81 views
0

我剛剛開始爲tvOS創建第一個應用程序,我很好奇它的手勢識別功能。有沒有可能爲tvOS使用PanGestureRecognizer?

我的目標是瞭解蘋果電視遙控器上手指滑動的方向和位移。

我知道如何檢測輕拍或輕掃,即使是輕掃的方向,但不是位移,換句話說,我不知道我將手指向上/向下/向左/向右移動了多少點。

如果有人知道如何做這樣的事情,請與我分享。

任何形式的幫助,高度讚賞。

回答

2

是的!檢查this蘋果指南瞭解更多信息。

輕擊手勢識別器可用於檢測按鈕按下。默認情況下,按下選擇按鈕 時觸發輕擊手勢識別器。 allowedPressTypes屬性用於指定哪個按鈕觸發識別器。

例子

檢測播放/暫停按鈕

let tapRecognizer = UITapGestureRecognizer(target: self, action: "tapped:") 
tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.PlayPause.rawValue)]; 
self.view.addGestureRecognizer(tapRecognizer) 

檢測輕掃手勢

let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: "swiped:") 
swipeRecognizer.direction = .Right 
self.view.addGestureRecognizer(swipeRecognizer) 

要獲得第l觸摸,請檢查Apples文檔中的Getting the Location of Touches部分。你需要使用locationInView

返回給定視圖的座標系統 中接收器的當前位置。

+0

謝謝你的回答,沒有意識到它會像在iOS上一樣工作:))結束了使用良好的舊UIPanGestureRecognizer –

相關問題