如何禁用默认的tvOS焦点动画?

问题描述 投票:2回答:3

我需要创建一个由UITableViewUITextField和一些自定义UIView混合的UI,我还需要提供自定义焦点动画。

我怎样才能让UITableView / UITableViewCellUITextField不渲染默认的焦点动画?

我试过了:

    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
        if let view = context.previouslyFocusedView {
            view.layer.removeAllAnimations()
        }
        if let view = context.nextFocusedView {
            view.layer.removeAllAnimations()
        }
    }

我可以添加自己的动画,但无法从视图中删除“默认”动画。

uitableview uitextfield tvos focus-engine
3个回答
2
投票

要从UITableViewCells中删除焦点,请使用以下代码:

 func tableView(_ tableView: UITableView, canFocusRowAt indexPath: IndexPath) -> Bool {
    return false
}

0
投票

将单元格的焦点样式更改为自定义而不是默认值。

cell.focusStyle = UITableViewCellFocusStyle.custom

0
投票

我已经解决了我的问题,类似于你的问题,但我的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()

    })

}

当表重新加载时,它会转换其未聚焦的形式,并且循环会重复。

© www.soinside.com 2019 - 2024. All rights reserved.