我需要创建一个由UITableView
,UITextField
和一些自定义UIView
混合的UI,我还需要提供自定义焦点动画。
我怎样才能让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
)
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()
})
}
当表重新加载时,它会转换其未聚焦的形式,并且循环会重复。