好吧,回答我的问题:)
所以显得有些有些意见是“可聚焦”上tvOS出的即装即用,和其他人必须被指示这样做。
我终于结束了使用UITextView
,它具有selectable
属性,但如果不是默认情况下这些可聚焦视图之一。必须禁用TextView
的编辑才能使其看起来像UILabel
。此外,目前存在一个错误,它可以防止您使用Interface Builder中的selectable
属性,但可以使用代码。
自然地,canBecomeFocused()
和也必须实施。您还需要通过UIViewController
,因为UITextView
无法呈现模态视图控制器。贝娄是我最终创造的。
class FocusableText: UITextView {
var data: String?
var parentView: UIViewController?
override func awakeFromNib() {
super.awakeFromNib()
let tap = UITapGestureRecognizer(target: self, action: "tapped:")
tap.allowedPressTypes = [NSNumber(integer: UIPressType.Select.rawValue)]
self.addGestureRecognizer(tap)
}
func tapped(gesture: UITapGestureRecognizer) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let descriptionView = storyboard.instantiateViewControllerWithIdentifier("descriptionView") as? DescriptionViewController {
if let view = parentView {
if let show = show {
descriptionView.descriptionText = self.data
view.modalPresentationStyle = UIModalPresentationStyle.OverFullScreen
view.presentViewController(descriptionView, animated: true, completion: nil)
}
}
}
}
override func canBecomeFocused() -> Bool {
return true
}
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
if context.nextFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.2).CGColor
}, completion: nil)
} else if context.previouslyFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.clearColor().CGColor
}, completion: nil)
}
}
}
感谢这个答案,我修改了一下我的项目。 https://gist.github.com/Cedrick84/8922a0af730c39c05794 – Cedrick
最近有什么改变与tvOS会导致这不起作用?无论我尝试什么,我仍无法获得TextView来获得焦点。我已经通过内核和@Cedrick走了两条路线。 –
是的,我为UIImageView做了类似的事情,我可以将它聚焦(即使它不在表格或collectionview中),但我无法使TextView工作。不知道为什么现在,因为我已经做了上面提到的所有事情 – c0d3Junk13