2016-09-27 3 views
1

그래서 Apple TV 원격 화살표 버튼 중 하나를 길게 누를 때 (터치 패드의 가장자리를 터치 할 때 트리거 됨) 화살표가 작동하지 않는 것처럼 보였습니다. 버튼을 클릭하십시오. 기본적으로 :tvOS : 화살 버튼을 길게 누르는 것을 감지 할 수 있습니까?

// This works 
let longSelectRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:))) 
longSelectRecognizer.allowedPressTypes = [UIPressType.Select.rawValue)] 
self.addGestureRecognizer(longSelectRecognizer) 

// This doesn't 
let longArrowRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:))) 
longArrowRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.LeftArrow.rawValue), NSNumber(integer: UIPressType.RightArrow.rawValue)] 
self.addGestureRecognizer(longArrowRecognizer) 

나는 UITouchGestureRecognizer로 교체 시도하지만 (예상대로) 화살표

답변

1

을 누른 때 나는이 믿고 감지하지 않습니다 위/아래/좌/우 - 화살표 때문에 가상 프레스입니다. 그들은 touchesBegan/Ended에서 다시 방송됩니다.

아래/위/오른쪽/왼쪽의 길게 누르기를 확인할 수있는 유일한 방법은 touchesBegan/Ended에서 touch.timestamp를 계산하는 것입니다.

var touchStart: TimeInterval? 

    override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
     touches.forEach({ touch in 
      switch touch.type{ 
       case .indirect: 
        self.touchStart = touch.timestamp 
       break 
       default: 
       break 
      } 

     }) 
    } 

    override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 
     touches.forEach({ touch in 
      switch touch.type{ 
       case .indirect: 
        if 
         let start = self.touchStart, 
         (touch.timestamp - start < 0.5){ 
         super.touchesEnded(touches, with: event) 
        }else { 
         self.performSegue(withIdentifier: SegueEnum.showOverlaySegue.rawValue, sender: nil) 
        } 
       break 
       default: 
       break 
      } 
     }) 
    } 
관련 문제