UIView
をフォーカス可能にすることはできますか?または、可能なすべてのビューに対してカスタムUIButton
を使用するだけですか?Apple TVでフォーカスエンジンを使用してUIViewをフォーカス可能にする方法
canBecomeFocused
を無効にしようとしましたが、何も起こりませんでした。
UIView
をフォーカス可能にすることはできますか?または、可能なすべてのビューに対してカスタムUIButton
を使用するだけですか?Apple TVでフォーカスエンジンを使用してUIViewをフォーカス可能にする方法
canBecomeFocused
を無効にしようとしましたが、何も起こりませんでした。
問題は、私の細胞に焦点が当てられていないことでした。 ":withAnimationCoordinator:didUpdateFocusInContext"
スウィフト2.3を重視した方法は、セルを強調表示することができるようにする:
これを包むために、あなたは1)オーバーライド
2)オーバーライドをcanBecomeFocused実装する必要があります
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.blueColor().colorWithAlphaComponent(0.2).CGColor
}, completion: nil)
} else if context.previouslyFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.clearColor().CGColor
}, completion: nil)
}
}
スウィフト3:
override var canBecomeFocused: Bool {
return true
}
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if context.nextFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.blue.withAlphaComponent(0.2).cgColor
}, completion: nil)
} else if context.previouslyFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.clear.cgColor
}, completion: nil)
}
}
物事が変わっていたし、現在のビューをフォーカス可能にする正しい方法はこのようです:
override var canBecomeFocused : Bool { return true }
スウィフトパベルのコードの3バージョン:
override var canBecomeFocused: Bool {
return true
}
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
if context.nextFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.blue.withAlphaComponent(0.2).cgColor
}, completion: nil)
} else if context.previouslyFocusedView == self {
coordinator.addCoordinatedAnimations({() -> Void in
self.layer.backgroundColor = UIColor.clear.cgColor
}, completion: nil)
}
}
はい、どんなのUIView canBecomeFocusedを使用してフォーカス可能です。ただし、フォーカスを表示するには、didUpdateFocusInContextメソッドをオーバーライドする必要もあります。 –