如何为自定义视图设置 canBecomeFocused [英] How do you set canBecomeFocused for a custom view
问题描述
我正在为 tvOS 制作应用程序.我有一个包含 UIButton
的视图和一个包含其他几个自定义视图的自定义 UIView
.模拟器只能突出显示 UIButton
而不是自定义视图.
I am making an application for tvOS. I have a view that contains a UIButton
and a custom UIView
that contains a couple other custom views. The simulator is only able to highlight the UIButton
and not the custom view.
如果您的自定义视图需要可聚焦,请覆盖 canBecomeFocused 以返回 YES(默认情况下,它返回 NO).
If your custom view needs to be focusable, override canBecomeFocused to return YES (by default, it returns NO).
canBecomeFocused 将返回
canBecomeFocused will return
YES,如果视图可以聚焦;否,否则.
YES if the view can become focused; NO otherwise.
但是,尝试通过这样做将 YES 分配给 canBecomeFocused:
However, attempting to assign YES to canBecomeFocused by doing this:
self.customView.canBecomeFocused = YES;
出现此错误:
No setter method 'setCanBecomeFocused:' for assignment to property
我该如何实现?
推荐答案
看起来 UIView
声明了函数/属性.
It looks like UIView
declares the function/property.
您是否尝试过覆盖这样的功能?
Have you tried overriding the function like so?
override func canBecomeFocused() -> Bool {
return true
}
目标-C
- (BOOL)canBecomeFocused {
return YES;
}
我没试过这个,但它可能对你有用.
I haven't tried this, but it may work for you.
这篇关于如何为自定义视图设置 canBecomeFocused的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!