簡體   English   中英

子視圖中的tvOS Focus按鈕

[英]tvOS Focus button in a Subview

我正在使用AVPlayerController,並且在AVPlayerController頂部添加了一個子視圖。 很快,將顯示子視圖,我想將焦點從播放器轉移到子視圖,並聚焦添加在該Subivew頂部的UIButton。 我嘗試了preferredfocusview,但是它是只讀屬性,因此無法更改。 任何人都可以幫忙。 非常感謝。

首先, preferredFocusView已棄用,因此應改為使用preferredFocusEnvironments

它是一個計算屬性,表示您沒有分配給它,而是將其覆蓋:

override var preferredFocusEnvironments: [UIFocusEnvironment] {
//if subview exists, return the subview or the button, whichever is focusable
    return [subview]
//otherwise use the default implementation of AVPlayerController
    return super.preferredFocusEnvironments
}

添加子視圖時,還應該調用self.setNeedsFocusUpdate()self.updateFocusIfNeeded()以請求焦點更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM