聚焦自定义 UITableCell 时移除细边框

kem*_*ica 2 swift tvos

题:

聚焦自定义 UITableCell 时,如何去除细长的白色边框?

(老实说它与单元格的边框无关,我尝试修改边框的颜色以查看)

描述:

这似乎只发生在我通过情节提要为表格单元格保留默认焦点样式时,当我删除单元格上的默认焦点动画时,不会出现白色边框(但随后我必须实现我自己的自定义动画.. )

我尝试使用不同的颜色和色调,但这似乎不起作用。

聚焦不同单元格时的边框

上面的 gif 显示聚焦特定 UITableCell 时出现的白色边框

我的 UITableViewController Storyboard 的屏幕截图。

UITableViewCell

上图是 UITableViewCell 的属性检查器的截图

我的 UITableViewCell 的内容视图

上图是我的 UITableViewCell 的内容视图的属性检查器的屏幕截图

表视图 上图是 UITableView 的属性检查器的截图

Arp*_*gre 5

更新:

这不是边界,而是阴影。现在UITableViewCellFocusStyle.default可能是在聚焦时为单元格设置阴影,当您滚动时,即使隐藏它后,阴影也会在短时间内可见。

您可以像这样隐藏阴影:

func tableView(_ tableView: UITableView, didUpdateFocusIn context: UITableViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
     if let cell = context.nextFocusedView as? CustomTableViewCell {
        cell.layer.shadowOpacity = 0
        cell.layer.masksToBounds = true
     }
     //other configurations
}
Run Code Online (Sandbox Code Playgroud)

注 1:使用上面的代码,阴影会出现很短的时间。使用下面的代码没有阴影。

或者,您可以像这样手动使用UITableViewCellFocusStyle.custom并提供没有阴影的默认焦点动画

func tableView(_ tableView: UITableView, didUpdateFocusIn context: UITableViewFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
    let xScale = 1.008
    let yScale = 1.008
    if let cell = context.nextFocusedView as? CustomTableViewCell {
           coordinator.addCoordinatedAnimations({ () -> Void in
                cell.transform = CGAffineTransform(scaleX: CGFloat(xScale), y: CGFloat(yScale))
            }, completion: nil)
    }

    if let previous = context.previouslyFocusedView as? CustomTableViewCell {
        coordinator.addCoordinatedAnimations({ () -> Void in
            previous.transform = CGAffineTransform.identity                
        }, completion: nil)
    }
    } 
Run Code Online (Sandbox Code Playgroud)

笔记:

尝试使用xScaleyScale值以获得更好的动画效果。