Pavel Smejkal Pavel Smejkal - 1 year ago 79
Swift Question

How to make a UIView focusable using the focus engine on Apple TV

Is it possible to make a

focusable? Or should I just use a custom
for all possible views?

I tried to override
but nothing happened.

Answer Source

So the problem was that I didn't notice that my cell got focus. To wrap this up, you need to implement

1) override canBecomeFocused

override func canBecomeFocused() -> Bool {
    return true

2) override "didUpdateFocusInContext:withAnimationCoordinator:" method to be able to highlight the cell as focused

override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {

    if context.nextFocusedView == self {

        coordinator.addCoordinatedAnimations({ () -> Void in

            self.layer.backgroundColor = UIColor.blueColor().colorWithAlphaComponent(0.2).CGColor

            }, completion: nil)

    } else if context.previouslyFocusedView == self {

        coordinator.addCoordinatedAnimations({ () -> Void in

            self.layer.backgroundColor = UIColor.clearColor().CGColor

            }, completion: nil)


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download