作者duckscorpion (歆)
看板MacDev
标题[问题] swift画线条後如何清除
时间Fri Dec 30 16:34:30 2016
目的是用动画让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://webptt.com/cn.aspx?n=bbs/MacDev/M.1483086875.A.165.html
1F:推 darktt: 可以看UIView.amimations(),或UIProertyAnimator 12/30 17:39
2F:推 kkk003: 要remove layer吧 12/30 19:47
3F:→ yuanruo: 给shapeLayer一个name 然後找subLayers,一样name就remove 12/30 19:56
4F:→ duckscorpion: 感谢 已顺利清除 12/30 20:52