【问题标题】:How can I disable the default tvOS focus animations?如何禁用默认的 tvOS 焦点动画?
【发布时间】:2016-08-25 21:06:25
【问题描述】:

我需要创建一个混合了UITableViewUITextField 和一些自定义UIView 的用户界面,并且我还需要提供自定义焦点动画。

如何让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()
        }
    }

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

【问题讨论】:

  • 如果你对它们进行子类化,你应该能够覆盖动画。
  • 我尝试覆盖/删除动画无济于事。
  • 描述你看到的动画。将您的代码放在UITableViewCell 子类中为我删除了所有动画。虽然removeAllAnimations() 调用是不必要的。
  • 我指的是 tvOS 为当前聚焦的视图绘制的略微放大和阴影效果。
  • 你发现了吗? @pstoppani

标签: uitableview uitextfield tvos focus-engine


【解决方案1】:

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

cell.focusStyle = UITableViewCellFocusStyle.custom

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 这是不正确的。问题是如何禁用默认的焦点动画而不阻止焦点在一个项目上。
    【解决方案3】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-18
      • 2021-10-23
      • 2021-10-25
      相关资源
      最近更新 更多