Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIBezierPath数组的动画绘制_Ios_Swift_Swift3_Core Animation_Uibezierpath - Fatal编程技术网

Ios UIBezierPath数组的动画绘制

Ios UIBezierPath数组的动画绘制,ios,swift,swift3,core-animation,uibezierpath,Ios,Swift,Swift3,Core Animation,Uibezierpath,我有一个UIBezierPath数组,它是从TouchsBegind和TouchsMoved点创建的。 我想在屏幕上画出它们的动画 不迭代每个bezier并调用setNeedsDisplay()的最佳方法是什么 谢谢 override func draw(_ rect: CGRect) { for bezier in beziers{ bezier.stroke() } } override func touchesBegan(_ tou

我有一个UIBezierPath数组,它是从TouchsBegind和TouchsMoved点创建的。 我想在屏幕上画出它们的动画

不迭代每个bezier并调用setNeedsDisplay()的最佳方法是什么

谢谢

  override func draw(_ rect: CGRect) {
      for bezier in beziers{
         bezier.stroke()
      }
   }
   override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
      super.touchesBegan(touches, with: event)
      let cgPoint = touches.first!.location(in: self)
      let bezierPath = ColorBezierPath() // subclass of UIBezierPath
      bezierPath.lineWidth = lineWidth
      bezierPath.color = color
      bezierPath.move(to: cgPoint)
      beziers.append(bezierPath)
   }

   override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
      super.touchesMoved(touches, with: event)
      let cgPoint = touches.first!.location(in: self)
      let bezierPath = beziers.last
      bezierPath?.addLine(to: cgPoint)
      setNeedsDisplay()
   }
override func draw(rect:CGRect){
bezier中的bezier{
bezier.stroke()
}
}
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
super.touchesbeated(touches,with:event)
让cgPoint=touchs.first!.location(在:self中)
设bezierPath=ColorBezierPath()//UIBezierPath的子类
bezierPath.lineWidth=线宽
bezierPath.color=颜色
bezierPath.move(到:cgPoint)
追加(bezierPath)
}
覆盖功能触摸移动(touchs:Set,带有事件:UIEvent?){
super.touchesMoved(touches,with:event)
让cgPoint=touchs.first!.location(在:self中)
让bezierPath=beziers.last
bezierPath?.addLine(到:cgPoint)
setNeedsDisplay()
}

您最好的选择是使用
CAShapeLayer
。它采用路径和各种其他设置。要设置动画,只需将其
strokeEnd
属性从
0.0
设置为
1.0
。这将创建从开始到结束绘制路径的效果,给定所需的动画计时参数:

let shapeLayer=CAShapeLayer()//strokeEnd的模型值默认为1.0
shapeLayer.frame=containerLayer.bounds
shapeLayer.path=bezierPath.cgPath
containerLayer.addSublayer(shapeLayer)
设strokeendaimation=cabasicaniation(关键路径:“strokeEnd”)
StrokeEndimation.duration=2.0
strokeEndimation.fromValue=0.0
添加(strokeendaimation,forKey:“strokeendaimation”)

您的要求是否与任何绘图应用程序相关?@PraveenKumar是的,类似于“绘制某物”,我想保存UIBezierPath数组,稍后在动画中显示绘图。您稍后说的是什么意思。。。当你画东西的时候,你不想给用户看吗?!我上面写的代码已经做到了。我的意思是稍后在其他设备上播放谢谢!由于某些原因,
shapeLayer.fillColor
默认设置为
.black
。产生了一种奇怪的效果。我花了一段时间才弄明白