我有一个自定义 UIView,它有一个 UIImageView 作为它的 subview 来显示图像和一个 CAShapeLayer 作为子层来绘制它。 UIView 是可缩放的,我使用 UIPinchGestureRecognizer 来放大和缩小 View 。我可以使用 CGPathRef 在 View 上绘制直线。问题是,当我捏缩放 View 时,我绘制的线条也会缩放并变粗。如何放大 View ,保持线条细?
缩放之前(绿线是我画的):
当我放大时:
我想要的是,线条要像我放大之前一样细。
我试过了:
CGMutablePath path = CGPathCreateMutable();
//line drawing code here
//scale path to 1.0?
CGAffineTransform transform = CGAffineTransformMakeScale(1.0, 1.0);
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(path, &transform);
self.drawingLayer.path = transformedPath;
CGPathRelease(path);
CGPathRelease(transformedPath);
缩放时如何防止路径宽度变大?
最佳答案
您需要将线宽除以缩放因子。默认线宽为 1。
因此,为相同创建属性,当您使用手势应用缩放时将其划分。
即缩放 = 4.0 然后线宽 = 1.0/4.0
与缩放为 2 然后为 1.0/2.0 相同
希望对您有所帮助
关于ios - 在可缩放的 UIView 中保留 CAShapeLayer 的 lineWidth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48616317/