【发布时间】:2023-06-18 05:51:01
【问题描述】:
我正在开发一个程序,它可以识别图像中的一个矩形,并在该识别的矩形的边界上绘制一条路径。现在我想重新定位该路径,以防它不在确切位置。例如看这张图片
在这种情况下,我需要拖动路径的角并将其重新定位为适合矩形。
为了绘制路径,我使用了 CAShapeLayer 和 UIBezierPath。这是我用来绘制路径的代码。
// imgView is the UIImageView which contains the image with the rectangle
let line: CAShapeLayer = CAShapeLayer();
line.frame = imgView.bounds;
let linePath: UIBezierPath = UIBezierPath();
linePath.moveToPoint(CGPointMake(x1, y1);
linePath.addLineToPoint(CGPointMake(x2, y2);
linePath.addLineToPoint(CGPointMake(x3, y3);
linePath.addLineToPoint(CGPointMake(x4, y4);
linePath.addLineToPoint(CGPointMake(x1, y1);
linePath.closePath();
line.lineWidth = 5.0;
line.path = linePath.CGPath;
line.fillColor = UIColor.clearColor().CGColor;
line.strokeColor = UIColor.blueColor().CGColor;
imgView.layer.addSublayer(line);
问题是我试图向 UIBezierPath 添加一个手势。但我注意到没有这样的事情。找不到任何关于此的内容。所以有人可以让我知道一种方法来完成我的工作。任何帮助将不胜感激。
【问题讨论】:
标签: ios swift uibezierpath cashapelayer