我正在使用 UIBezierPath
和 CAShapeLayer
绘制一条线并将其作为子图层添加到 View 中。一切正常,现在我必须调整“Line”及其父 View 的大小,并严格保持线条与 View 的比例相同。
这是创建一行的代码:
let line = UIBezierPath.arrow(from: startPoint, to: endPoint, tailWidth: 5, headWidth: 20, headLength: CGFloat(inputLength * 0.1))
let shapeLayer = CAShapeLayer()
shapeLayer.path = line .cgPath
self.view.layer.addSublayer(shapeLayer)
最佳答案
我想你可以缩放保存路径的 View ,例如
let scaleWidth = toSize.width / fromSize.width
let scaleHeight = toSize.height / fromSize.height
path.apply(CGAffineTransform(scaleX: scaleWidth, y: scaleHeight))
并使用比例因子来获取路径的某个点
关于ios - Swift:根据父 View 大小动态调整/缩放 UIBezierPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44602948/