0
具体的には底面に影をつける必要がありますUITableViewCell
。私はそれを作ったが、下にスクロールするとうまくいきます。上にスクロールすると、影が間違っていて、それはUITableViewCell
の上に現れます。私はいくつかの方法を試しましたが、それは私のためには機能しません。私はこれを読むquestionとこれはquestion私はそれを修正することができますか?UITableViewのスクロール後にCAGradientLayerの位置が正しくありません。 Swift
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
}
私はそれを試しましたが、それは私のためには機能しません – Alexander
'shadowView'を削除する必要がありますか?例えば、シャドウビューを削除するには、そのプロパティを 'tag'とします。 – RrrangeTop