【发布时间】:2015-12-22 11:33:53
【问题描述】:
我期待在 tvOS 中获得焦点视图的大小。
我需要它的大小才能将标签从视图中移动到适合焦点框架的新位置。
【问题讨论】:
我期待在 tvOS 中获得焦点视图的大小。
我需要它的大小才能将标签从视图中移动到适合焦点框架的新位置。
【问题讨论】:
我认为您正在寻找的是UIImageView 提供的focusedFrameGuide。
使用imageview.focusedFrameGuide.layoutFrame,您可以确定如何重新定位您的标签。
【讨论】:
adjustsImageWhenAncestorFocused 时'frame 与focusedFrameGuide 不同。所以我认为它可能对你有用。
使用自动布局需要设置两个约束:
focusedConstraint = label.topAnchor.constraint(equalTo: imageView.focusedFrameGuide.bottomAnchor)
unfocusedConstraint = label.topAnchor.constraint(equalTo: imageView.bottomAnchor)
并在didUpdateFocus 上激活/停用:
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocus(in: context, with: coordinator)
if context.nextFocusedView == self {
unfocusedConstraint?.isActive = false
focusedConstraint?.isActive = true
} else if context.previouslyFocusedView == self {
focusedConstraint?.isActive = false
unfocusedConstraint?.isActive = true
}
coordinator.addCoordinatedAnimations({
self.layoutIfNeeded()
}, completion: nil)
}
【讨论】: