Uitableview 如何禁用默认的tvOS焦点动画?
我需要创建一个UI,它是Uitableview 如何禁用默认的tvOS焦点动画?,uitableview,uitextfield,tvos,focus-engine,Uitableview,Uitextfield,Tvos,Focus Engine,我需要创建一个UI,它是UITableView、UITextField和一些自定义的UIView的混合体,我还需要提供一个自定义焦点动画 如何使UITableView/UITableViewCell和UITextField不渲染默认焦点动画 我试过: override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimat
UITableView
、UITextField
和一些自定义的UIView
的混合体,我还需要提供一个自定义焦点动画
如何使UITableView
/UITableViewCell
和UITextField
不渲染默认焦点动画
我试过:
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
if let view = context.previouslyFocusedView {
view.layer.removeAllAnimations()
}
if let view = context.nextFocusedView {
view.layer.removeAllAnimations()
}
}
我可以添加自己的动画,但无法从视图中删除“默认”动画。要从UITableViewCells中删除焦点,请使用以下代码:
func tableView(_ tableView: UITableView, canFocusRowAt indexPath: IndexPath) -> Bool {
return false
}
将单元格的焦点样式更改为“自定义”,而不是“默认”
cell.focusStyle = UITableViewCellFocusStyle.custom
我已经解决了与您的问题类似的问题,但我的
UITableView
只有一个UITableViewCell
。因此,当UIViewController显示/加载时,没有聚焦的UITableViewCell,当我单击该单元格时,它将执行其操作(显示一个UIAlertController
)
然后
当表格重新加载时,它将转换其未聚焦的形式,循环将重复自身。如果对其进行子类化,则应该能够覆盖动画。我尝试覆盖/删除动画,但没有效果。请描述您看到的动画。将代码放入
UITableViewCell
子类中,为我删除了所有动画。尽管removeAllimations()
调用是不必要的。我指的是tvOS为当前聚焦的视图绘制的略微放大和缩小的阴影效果。你明白了吗@这是不正确的。问题是如何禁用默认的聚焦动画而不阻止聚焦在某个项目上。
if let focusedCell = UIScreen.main.focusedView as? MyCell{
focusedCell.backgroundColor = UIColor.clear
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// take action
... alertController configuration
present(alertController, animated: true, completion: {
tableView.reloadData()
})
}