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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With