2017-11-15 16 views
0

UIButton의 하위 클래스를 만들고 있는데 터치를 가로 채려고하는 이유는 '누르기'또는 '프레스 종료'이벤트를 수신 할 다른 방법을 찾는 것 같습니다. tvOS의 표준 UIButton입니다. 그렇게 할 수있는 방법을 찾을 수 있다면 아래의 해결책을 고민 할 필요가 없습니다.tvOS : pressesEnded가 간헐적으로 호출됩니다.

pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) Apple TV 리모컨의 '선택'버튼을 누를 때마다 전화가 걸리지 않는 것처럼 보입니다.

pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?)은 매번 문제없이 호출됩니다. 아래 코드를 첨부했습니다. 어떤 아이디어가이 문제를 일으킬 수 있습니까?

class EVLPTZButton: UIButton 
{ 
    var command: PTZCommand! 
    var delegate: EVLPTZButtonCommandDelegate? 

    override func pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) 
    { 
    super.pressesBegan(presses, with: event) 

    delegate?.ptzButton(pressesBeganFor: self, with: command) 
    } 

    override func pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?) 
    { 
    super.pressesEnded(presses, with: event) 

    delegate?.ptzButton(pressesEndedFor: self) 
    } 
} 
+0

왜 버튼에 대한 프레스 이벤트가 필요한지에 대해 설명 할 수 있습니까? 버튼을 눌렀을 때를 알고 싶다면'addTarget (_ : action : for :)'메서드를 사용하여'.primaryActionTriggered' 이벤트에 대한 코드를 등록 할 수 있습니다. –

+0

버튼의 초점 및/또는 강조 표시된 상태를 더 성공적으로 볼 수 있습니다. – picciano

답변

0

후 좀 더는 '선택'버튼을 놓을 때 tvOS 중 하나 pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)또는pressesCancelled(_ presses: Set<UIPress>, with event: UIPressesEvent?)를 호출하는 것으로 보인다 테스트.

나는 pressesEnded(_ presses: Set<UIPress>, with event: UIPressesEvent?)의 정의에 점프하고이 댓글을 찾아이 솔루션을 발견 :

pressesEnded 중 하나를 받게됩니다 귀하의 응답 : withEvent 또는 pressesCancelled : withEvent : 누를 때마다 것이 처리됩니다 (그 프레스 그것은 pressesBegan : withEvent :)에서 받았습니다.

+1

제스처 인식기가 버튼 누르기를 처리하기 시작하면 'pressesCancelled'가 호출됩니다. 따라서 이것은 정상적으로 예상되는 동작입니다. 언론이 취소 된 것으로보고 될 수있는 다른 이유가 있지만 가장 일반적인 이유입니다. –