0
是否有可能使UIImageView
成爲焦點?或者我應該只使用UICollectionView
所有可能的視圖?如何在Apple TV上使用焦點引擎製作UIImageView可聚焦
我試圖覆蓋canBecomeFocused
但沒有任何發生。
是否有可能使UIImageView
成爲焦點?或者我應該只使用UICollectionView
所有可能的視圖?如何在Apple TV上使用焦點引擎製作UIImageView可聚焦
我試圖覆蓋canBecomeFocused
但沒有任何發生。
我發現的最簡單的方法是繼承UIButton而不是UIImageView(因爲UIButton已經有一個圖像子視圖)。您可能並不需要我放在那裏(重要的部分是在layoutSubviews中設置imageView?.adjustsImageWhenAncestorFocused = true)
class AtvImageButton:UIButton
{
override func awakeFromNib()
{
super.awakeFromNib()
contentMode = UIViewContentMode.ScaleAspectFit
contentHorizontalAlignment = .Fill
contentVerticalAlignment = .Fill
}
override func layoutSubviews()
{
imageView?.adjustsImageWhenAncestorFocused = true
imageView?.clipsToBounds = false
super.layoutSubviews()
}
override func canBecomeFocused() -> Bool
{
return enabled && super.canBecomeFocused()
}
}