[英]Changing the zPosition of the collectionView cell in tvOS in Swift
[英]How to move focus at button in collectionview cell in tvos application?
我正在研究Apple TV應用程序。 在我的應用程序中,我制作了一個具有收藏夾視圖的屏幕。 在那種情況下,我可以將焦點移到集合視圖單元格上,但是不能將焦點移到集合視圖單元格中的按鈕上,那么有人可以幫助我解決此問題嗎?
如果有人知道這個答案,請給我一個答案。
我可以通過在collectionViewCell子類中添加以下方法來解決此問題。
override var preferredFocusEnvironments: [UIFocusEnvironment]{
// Condition
}
override func shouldUpdateFocus(in context: UIFocusUpdateContext) -> Bool {
// Condition
}
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
// Condition
}
您可以在此鏈接中看到更多信息: 在此處輸入鏈接描述 。
我認為此頁面將指導您實現所需的內容。 https://developer.apple.com/library/content/documentation/General/Conceptual/AppleTV_PG/WorkingwiththeAppleTVRemote.html#//apple_ref/doc/uid/TP40015241-CH5-SW4
它很好地說明了焦點引擎如何決定哪個對象應該獲得下一個焦點。 下面是以上鏈接的逐步詳細說明。
這是顯示如何確定焦點的示例:
您必須重寫UIView或UIViewController的preferredFoucsedView屬性。
override weak var preferredFocusedView: UIView? {
if someCondition {
return theViewYouWant
} else {
return defaultView
}
}
感謝Slayter的回答
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.