gpt4 book ai didi

ios - JTAppleCalendar - 如何停止单元格随机重复?

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

我在 cellForItemAt 方法中针对特定条件绘制一个圆圈,如下所示:

    if cellState.date == CalendarModel.DUE_DATE {
let shapeLayer = CAShapeLayer()

let circlePath = UIBezierPath(arcCenter: CGPoint(x: (cell.layer.frame.size.width)/2,y: (cell.layer.frame.size.height)/2), radius: CGFloat(15), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true)


shapeLayer.path = circlePath.cgPath

//change the fill color
shapeLayer.fillColor = UIColor.clear.cgColor
//you can change the stroke color
shapeLayer.strokeColor = UIColor.FlatColor.Blue.midnightBlue.cgColor
//you can change the line width
shapeLayer.lineWidth = 1.0
cell.layer.addSublayer(shapeLayer)
}

圆圈不断随机重复。我正在 willDisplayCell 中尝试以下代码,但它会删除单元格中的所有内容。

func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
// comment
cell.layer.sublayers?.forEach { $0.removeFromSuperlayer() }
}

如何专门删除cellForItemAt中添加的shapeLayer?任何帮助将不胜感激。谢谢。

最佳答案

根据 @Paulw11 的建议,我对 JTAppleCell 进行了子类化并添加了一个变量,如下所示:

    var shapeLayer : CAShapeLayer!

然后在同一个 JTAppleCell 的子类中添加另一个方法,如下所示:

func addCircle() {
self.shapeLayer = CAShapeLayer()
let circlePath = UIBezierPath(arcCenter: CGPoint(x: (self.layer.frame.size.width)/2,y: (self.layer.frame.size.height)/2), radius: CGFloat(15), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true)
shapeLayer.path = circlePath.cgPath
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = UIColor.FlatColor.Blue.cgColor
shapeLayer.lineWidth = 1.0
self.layer.addSublayer(shapeLayer)
}

cellForItemAt 中,我在将 else block 中的单元格出队后添加了以下几行:

if cell.shapeLayer != nil {
cell.shapeLayer.removeFromSuperlayer()
cell.shapeLayer = nil
}

谢谢@Paulw11,上述解决方案对我有用。

关于ios - JTAppleCalendar - 如何停止单元格随机重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47518452/

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