Ronny Westwood
Ronny Westwood

Reputation: 43

iOS TV button menu & image

I started a basic iOS TV project.. As you see in image I've created different system buttons and an image object. If I try it on simulator I can move from buttons with keyboard and also with TV Remote Controller without any code. Now, I would like to change the Image whenever I select any different buttons. for example: if I'm on Button1 I want display Image1, if I go to button6 I want display Image6 and so on... but I can't find a way to make it possible (I know the button, the button state, outlet and action)... can anyone help me? I would not start again from zero... I like the apple system buttons... thanks

ViewController

Upvotes: 1

Views: 124

Answers (1)

picciano
picciano

Reputation: 22701

Implement the following method in your view controller to detect changes in focus. Then just look at the nextFocusedView and update your image as needed. You might want to set the tag property on the buttons and use a switch statement, but there are many ways to figure out which button is selected.

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    guard let nextFocusedView = context.nextFocusedView,
          let previouslyFocusedView = context.previouslyFocusedView else {
        return
    }

    // Update image based on nextFocusedView
}

Upvotes: 1

Related Questions