gpt4 book ai didi

ios - CAGradientLayer 在 UITableView 中滚动到顶部后位置错误。 swift

转载 作者:行者123 更新时间:2023-11-29 00:49:00 25 4
gpt4 key购买 nike

我需要在特定 UITableViewCell 的底部制作阴影。我做到了,但是当我滚动到底部时它工作正常,当我滚动到顶部时阴影位置错误并且它出现在 UITableViewCell 的顶部。我尝试了多种方法,但对我不起作用。我读了这个question还有这个question我该如何解决?

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier, forIndexPath: indexPath) as! LifelineLeaderboardTableViewCell

// Configure the cell...
let lifelineRecentModel = users[indexPath.row]

cell.clipsToBounds = false
if let currentUserID = DBHelper.instance.mainUserId {
if lifelineRecentModel.user.id == currentUserID {
cell.setupUserNumberLabelTextColor(true)
cell.showBlueLineView(true)
// cell.showShadow(true)
let shadowView = UIView(frame: cell.bounds)

let shadowFrame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: cell.bounds.width, height: 90))
let shadowPath = UIBezierPath(rect: shadowFrame).CGPath
let shadow = CAGradientLayer()

shadow.shadowOpacity = 0.25
shadow.shadowColor = UIColor.blackColor().CGColor
shadow.shadowPath = shadowPath
shadowView.layer.insertSublayer(shadow, atIndex: 0)
cell.contentView.addSubview(shadowView)
} else {
cell.setupUserNumberLabelTextColor(false)
cell.showBlueLineView(false)
// cell.showShadow(false)
}
} else {
cell.setupUserNumberLabelTextColor(false)
cell.showBlueLineView(false)
// cell.showShadow(false)
}

return cell
}

我还尝试了以下功能

  func showShadow(bool: Bool) {
let shadowFrame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: bounds.width, height: bounds.height + 10))
let shadowPath = UIBezierPath(rect: shadowFrame).CGPath

layer.shadowOpacity = 0.25
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowPath = shadowPath
clipsToBounds = !bool
}

我也试过了

        cell.clipsToBounds = false
if let currentUserID = DBHelper.instance.mainUserId {
if lifelineRecentModel.user.id == currentUserID {
cell.setupUserNumberLabelTextColor(true)
cell.showBlueLineView(true)
// cell.showShadow(true)
cell.layer.shadowPath = UIBezierPath(rect: cell.bounds).CGPath
cell.layer.shadowOpacity = 0.5
cell.layer.shadowOffset = CGSize(width: 0, height: 10)

} else {
cell.setupUserNumberLabelTextColor(false)
cell.showBlueLineView(false)
// cell.showShadow(false)
cell.layer.shadowOpacity = 0

}
} else {
cell.setupUserNumberLabelTextColor(false)
cell.showBlueLineView(false)
// cell.showShadow(false)
cell.layer.shadowOpacity = 0
}

最佳答案

我认为你应该从不能包含阴影的单元格中“移除”阴影。像这样

if let currentUserID = DBHelper.instance.mainUserId {
..........
} else {
.......
shadow.shadowColor = UIColor.clearColor().CGColor
}

你能添加屏幕截图的“坏”单元格吗?

关于ios - CAGradientLayer 在 UITableView 中滚动到顶部后位置错误。 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38325727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com