[問題] swift畫線條後如何清除

看板MacDev作者 (歆)時間8年前 (2016/12/30 16:34), 編輯推噓2(202)
留言4則, 4人參與, 最新討論串1/1
目的是用動畫讓Label移動並劃出軌跡 但是再次實行後無法消除上次留下的軌跡 用setNeedsLayout或setNeedsDisplay都無效 另外還想問問還有什麼方式可以不使用CA開頭的物件來作動畫效果 因為裡面的keyPath官方文件都沒有相關資料可查效果 下面是我的code self.view.setNeedsLayout() self.view.layer.setNeedsLayout() let path=UIBezierPath() ... let anim=CAKeyframeAnimation(keyPath:"position") anim.path=path.cgPath anim.repeatCount=1 anim.duration=5.0 self.myLabel.layer.add(anim, forKey: "Path") let progressLine = CAShapeLayer() progressLine.path = path.cgPath progressLine.strokeColor = UIColor.blue.cgColor progressLine.fillColor = UIColor.clear.cgColor progressLine.lineWidth = 10.0 let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd") animateStrokeEnd.duration = 5.0 animateStrokeEnd.fromValue = 0.0 animateStrokeEnd.toValue = 1.0 progressLine.add(animateStrokeEnd, forKey: "animate stroke end animation") self.view.layer.addSublayer(progressLine) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.76.46 ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1483086875.A.165.html

12/30 17:39, , 1F
可以看UIView.amimations(),或UIProertyAnimator
12/30 17:39, 1F

12/30 19:47, , 2F
要remove layer吧
12/30 19:47, 2F

12/30 19:56, , 3F
給shapeLayer一個name 然後找subLayers,一樣name就remove
12/30 19:56, 3F

12/30 20:52, , 4F
感謝 已順利清除
12/30 20:52, 4F
文章代碼(AID): #1OPXmR5b (MacDev)
文章代碼(AID): #1OPXmR5b (MacDev)