聚焦自定义 UITableCell 时移除细边框
Remove thin-like border when focusing a custom UITableCell
问题:
如何在聚焦自定义 UITableCell 时去除细细的白色边框?
(老实说跟单元格的边框没有关系,我试过修改边框的颜色看看)
描述:
这似乎只发生在我通过故事板为 table 单元格保留默认焦点样式时,当我删除单元格上的默认焦点动画时,白色边框不会出现(但后来我必须实现我自己的自定义动画..)
我试过尝试不同的颜色和色调,但似乎没有用。
上面的 gif 显示了聚焦特定 UITableCell 时出现的白色边框
我的 UITableViewController 故事板的屏幕截图。
上图是 UITableViewCell 属性检查器的屏幕截图
上图是我的 UITableViewCell 的内容视图的属性检查器的屏幕截图
上图是 UITableView 的属性检查器的屏幕截图
将您的单元格焦点样式更改为自定义
更新:
不是边框,是阴影。现在 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
}
注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)
}
}
注:
尝试使用 xScale & yScale 值以获得更好的动画效果。
问题:
如何在聚焦自定义 UITableCell 时去除细细的白色边框?
(老实说跟单元格的边框没有关系,我试过修改边框的颜色看看)
描述:
这似乎只发生在我通过故事板为 table 单元格保留默认焦点样式时,当我删除单元格上的默认焦点动画时,白色边框不会出现(但后来我必须实现我自己的自定义动画..)
我试过尝试不同的颜色和色调,但似乎没有用。
上面的 gif 显示了聚焦特定 UITableCell 时出现的白色边框
我的 UITableViewController 故事板的屏幕截图。
上图是 UITableViewCell 属性检查器的屏幕截图
上图是我的 UITableViewCell 的内容视图的属性检查器的屏幕截图
将您的单元格焦点样式更改为自定义
更新:
不是边框,是阴影。现在 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
}
注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)
}
}
注:
尝试使用 xScale & yScale 值以获得更好的动画效果。