大佬教程收集整理的这篇文章主要介绍了ios – 快速绘制手绘形状,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
怎么可能呢?
TIA
let path = UIBezierPath() path.move(to: from) path.addLine(to: to) let shapeLayer = CAShapeLayer() shapeLayer.path = path.cgPath shapeLayer.strokeColor = lineColor.cgColor shapeLayer.lineWidth = 1.0 view.layer.addSublayer(shapeLayer)
override func touchesBegan(_ touches: Set<UITouch>,with event: UIEvent?) { let touch = event?.allTouches?.first let touchLOCATIOn: CGPoint? = touch?.LOCATIOn(in: self.view) //---Declare "from" globally as CGPoint from = CGPoint(x: (touchLOCATIOn?.X)!,y: (touchLOCATIOn?.y)!) } override func touchesMoved(_ touches: Set<UITouch>,with event: UIEvent?) { let touch = event?.allTouches?.first let touchLOCATIOn: CGPoint? = touch?.LOCATIOn(in: self.view) //--Get New touch point let to = CGPoint(x: (touchLOCATIOn?.X)!,y: (touchLOCATIOn?.y)!) //--Draw line drawLineFromPoint(from: from,to: to,ofColor: UIColor.red,inView: self.view) //--Save as older point from = to } func drawLineFromPoint(from : CGPoint,to:CGPoint,ofColor lineColor: UIColor,inView view:UIView) { //design the path let path = UIBezierPath() path.move(to: from) path.addLine(to: to) //design path in layer let shapeLayer = CAShapeLayer() shapeLayer.path = path.cgPath shapeLayer.strokeColor = lineColor.cgColor shapeLayer.lineWidth = 1.0 view.layer.addSublayer(shapeLayer) }
以上是大佬教程为你收集整理的ios – 快速绘制手绘形状全部内容,希望文章能够帮你解决ios – 快速绘制手绘形状所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。