ios - Swift:根据父 View 大小动态调整/缩放 UIBezierPath

标签 ios swift resize uibezierpath cashapelayer

我正在使用 UIBezierPathCAShapeLayer 绘制一条线并将其作为子图层添加到 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/

相关文章:

ios - UITableViewCell systemLayoutSizeFittingSize 额外增加 0.5 px

ios - SKAction 未删除 Sprite

swift - 如何在 Swift/Cocoa 应用程序中获取 HID 设备列表?

ios - 在 Soap iOS 中为服务器发送 Api 请求数组

ios - 删除从 Controller 添加的导航栏中的自定义 subview

jquery - 我可以检测浏览器调整大小事件吗?

jquery + flash : looking for plugin that resize images before upload

android - 如何在不包含 Ionic.js 的情况下使用 Ionic Framework 创建应用程序

jQuery - 使高值与宽度值相同

ios - 自定义 UISlider 无图像