问题描述
所以我在View中有一个TableView,并且我不想在Tableview的顶部和底部使用默认的渐变,因为在滚动时它会显示在行单元格上。它是这样的:
所以我设置了
self.tableView.mask = nil
我还尝试向TableViewCell添加一个遮罩以隐藏它们,向下滚动效果很好,但是当向上滚动时,有时会出现故障,有一段时间,我在表格视图上方看到了它们,然后消失了。这就是我添加该蒙版的方式。
func maskCell(cell: UITableViewCell,fromTopWithMargin margin: CGFloat) {
cell.layer.mask = self.visibilityMaskForCell(cell: cell,withLocation: margin / cell.frame.size.height)
cell.layer.masksToBounds = true
}
func visibilityMaskForCell(cell: UITableViewCell,withLocation location: CGFloat) -> CAGradientLayer {
let mask = CAGradientLayer()
mask.frame = cell.bounds
mask.colors = [UIColor.black.withAlphaComponent(0.0).cgColor,UIColor.black.cgColor]
mask.locations = [NSNumber(value: Float(location)),NSNumber(value: Float(location))]
return mask
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
logMilestone("\(self.tableView.visibleCells)")
for cell in self.tableView.visibleCells {
let hiddenFrameHeight = scrollView.contentOffset.y - cell.frame.origin.y
if hiddenFrameHeight >= 0 || hiddenFrameHeight <= cell.frame.size.height {
self.maskCell(cell: cell,fromTopWithMargin: hiddenFrameHeight)
}
}
}
有没有可能的解决方法
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)