Madu
Madu

Reputation: 5039

UIImageView not gets Focused on tvOS

I have the following UIViewController which i am doing in story board.

StoryBoad

The problem i am facing here is that when i try to swipe right on tv remote my UIImageView does not get any focus. Infact no focus event happen, it try to put some logs in

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

but there is no focus event updated. Earlier i have UIImageView directly added on self.view in storyboard but i read somewhere the UIImageView itself is not focusable so i put my UIImageView inside another UIView, but it still does not gets any focus. I have aligned top edges of UIView which contains UIImageView and UITextView.

Any help will be highly appreciated

On a side note i also tried to do with UIFocusGuide but that didn't work also. I think i don't need to use UIFocusGuide because it a basic right swipe focus thing.

Upvotes: 2

Views: 2391

Answers (3)

Fattie
Fattie

Reputation: 12363

It is now extremely easy to focus an image view in AppleTV, with all the effects included:

Your image will be part of table view or collection view. Then just set

adjustsImageWhenAncestorFocused = true

That's all it is.

Upvotes: 0

yuhua
yuhua

Reputation: 1249

@C_X is right. The most important thing is that if UIImageView is added to self.view then don't forget to subclass self.view and override the canBecameFofused method.

Upvotes: 2

Adnan Aftab
Adnan Aftab

Reputation: 14477

UIImageView is not by default focusable, and will not get focus effect, you can do two things to make it focusable.

  1. Subclass UIImageView and in subclass override canBecameFocused and return YES, and then override didUpdateFoucsInContext and update appearance for focus state, like if focus make it bigger or change color etc.
  2. Second option is add it to a view which is focusable and then set imageView.adjustImageWhenAncestorFocused = YES also set clipToBounds = NO on superview

So In your case as you are adding imageView to a view then that view should return YES/True from canBecameFocused.

Upvotes: 10

Related Questions