請記住,tvOS沒有像觸摸屏幕那樣的「觸摸」的概念。
處理「水龍頭」的官方方式是使用UITapGestureRecognizer。當物品處於焦點狀態時,用戶點擊/點擊遙控器即可。
這裏是我正在做它用UICollectionView工作:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MovieCell", forIndexPath: indexPath) as? MovieCell {
let movie = movies[indexPath.row]
cell.configureCell(movie)
if cell.gestureRecognizers?.count == nil {
let tap = UITapGestureRecognizer(target: self, action: "tapped:")
tap.allowedPressTypes = [NSNumber(integer: UIPressType.Select.rawValue)]
cell.addGestureRecognizer(tap)
}
return cell
} else {
return MovieCell()
}
}
func tapped(gesture: UITapGestureRecognizer) {
if let cell = gesture.view as? MovieCell {
//Load the next view controller and pass in the movie
print("Tap detected...")
}
}
你可以抓住的自來水從獲取傳遞在處理函數的UITapGestureRecognizer位置。
還看到蘋果電視上看到這個教程: https://www.youtube.com/watch?v=XmLdEcq-QNI
你的權利!印刷機開始,坎塞爾,結束 - 一切正常。我們需要一個觸摸式 - 在觸摸屏上有X和Y的位置! – user2545883
@ user2545883如果它解決了您的問題,請將其標記爲正確答案,以便具有相同問題的其他人知道這是解決方案 – Chris