我是UIBezIErPath的新手.我尝试过以下代码,但它没有按照我的意愿运行.
怎么可能呢?
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)解决方法 你好@Rajinder为此你必须获得接触点,所以你必须使用
以下方法.
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 – 快速绘制手绘形状所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)