Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What events are produced by UIControl on tvOS?

Tags:

tvos

With UIButton, tvOS produces UIControlEvents.PrimaryActionTriggered (not .TouchUpInside, as it does on iOS) when the button gets focus and the user taps on the remote.

UIControl's don't seem to produce either of these events, however. I can't see that it produces any events, in fact, when the user focuses on the control and taps on the remote.

How does one use a custom UIControl for tvOS?

like image 971
Stephen Farrell Avatar asked Sep 16 '15 19:09

Stephen Farrell


1 Answers

A UIControl doesn't emit any control events of its own accord. Your subclass is responsible for emitting events (generally by sending itself sendActionsForControlEvents:).

Since UIControl isn't currently documented for tvOS, it might be that Apple doesn't want you to subclass it.

Anyway, I've only played around with it a little, but apparently to implement your own UIControl subclass, you must override canBecomeFocused to return YES, and you must override pressesEnded:withEvent: to act on the user's press (presumably by sending yourself sendActionsForControlEvents:.).

You might also want to override pressesBegan:withEvent: to highlight your control.

Because UIControl conforms to the UIFocusEnvironment protocol (by way of UIView), you can override didUpdateFocusInContext:withAnimationCoordinator: to update your control's appearance depending on whether it has focus.

like image 52
rob mayoff Avatar answered Oct 07 '22 13:10

rob mayoff