简体   繁体   English

UIImageView没有专注于tvOS

[英]UIImageView not gets Focused on tvOS

I have the following UIViewController which i am doing in story board. 我有以下UIViewController ,我在故事板上做。

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. 我面临的问题是,当我尝试在电视遥控器上向右滑动时,我的UIImageView没有得到任何关注。 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. 之前我在故事板中直接在self.view上添加了UIImageView ,但我在某处读到了UIImageView本身不可聚焦,所以我把我的UIImageView放在另一个UIView ,但它仍然没有得到任何关注。 I have aligned top edges of UIView which contains UIImageView and UITextView . 我已经对齐了包含UIImageViewUITextViewUIView顶部边缘。

Any help will be highly appreciated 任何帮助将受到高度赞赏

On a side note i also tried to do with UIFocusGuide but that didn't work also. 另外,我还尝试使用UIFocusGuide,但这也不起作用。 I think i don't need to use UIFocusGuide because it a basic right swipe focus thing. 我想我不需要使用UIFocusGuide,因为它是一个基本的右滑动焦点的东西。

UIImageView is not by default focusable, and will not get focus effect, you can do two things to make it focusable. UIImageView默认情况下不是可聚焦的,并且不会获得焦点效果,你可以做两件事来使它具有焦点。

  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. 子类UIImageView和子类覆盖canBecameFocused并返回YES ,然后覆盖didUpdateFoucsInContext并更新焦点状态的外观,如焦点使其变大或更改颜色等。
  2. Second option is add it to a view which is focusable and then set imageView.adjustImageWhenAncestorFocused = YES also set clipToBounds = NO on superview 第二个选择是将其添加到图,该可获得焦点,然后设置imageView.adjustImageWhenAncestorFocused = YES还设置clipToBounds = NOsuperview

So In your case as you are adding imageView to a view then that view should return YES/True from canBecameFocused. 因此,在您将viewView添加到视图的情况下,该视图应该从canBecameFocused返回YES / True。

@C_X is right. @C_X是对的。 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. 最重要的是,如果UIImageView添加到self.view然后不要忘记继承self.view并重写canBecameFofused方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM