ios – 快速绘制手绘形状

ios – 快速绘制手绘形状,第1张

概述我想绘制一些形状,如某人的签名或其他一些写意形状.  我是UIBezierPath的新手.我尝试过以下代码,但它没有按照我的意愿运行. 怎么可能呢? TIA let path = UIBezierPath() path.move(to: from) path.addLine(to: to) let shapeLayer = CAShapeLayer() shap 我想绘制一些形状,如某人的签名或其他一些写意形状.
我是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 – 快速绘制手绘形状所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1099313.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存