tvos抑制白焦效应

tvos suppress white focus effect

我正在使用此代码设置焦点上 UITableViewCells 的颜色:

class EpisodesTableViewCell: UITableViewCell {

    override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {

        super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)

        if let previous = context.previouslyFocusedView as? EpisodesTableViewCell {
            previous.contentView.backgroundColor = UIColor.clearColor()
        }
        if let next = context.nextFocusedView as? EpisodesTableViewCell {
            next.contentView.backgroundColor = globalDarkGrey
        }
    }
}

颜色会根据需要改变,但从一行 table 行移动到另一行时,通常会出现短暂(而且相当烦人)的白色焦点颜色闪烁。

通过不调用 super 我避免了闪光,但失去了点击动画。

关于如何完全摆脱白色的任何想法?

尝试改变里面的背景颜色 addCoordinatedAnimations:

coordinator.addCoordinatedAnimations {
        if let previous = context.previouslyFocusedView as? EpisodesTableViewCell {
            previous.contentView.backgroundColor = UIColor.clearColor()
        }
        if let next = context.nextFocusedView as? EpisodesTableViewCell {
            next.contentView.backgroundColor = globalDarkGrey
        }
}

上面的答案足够接近我的答案,但这里是可用的形式:

coordinator.addCoordinatedAnimations({
    if let previous = context.previouslyFocusedView as? EpisodesTableViewCell {
        previous.contentView.backgroundColor = UIColor.clearColor()
    }
    if let next = context.nextFocusedView as? EpisodesTableViewCell {
        next.contentView.backgroundColor = globalDarkGrey
    }
    }, completion: nil)