我正在为绘图应用程序库添加一项新功能,并且我正在为其实施捏合调整大小功能。例如,我有一个通过连接 2
CGPoint
s 创建的线形。我想通过使用 UIPinchGestureRecognizer
来增加形状的大小,因为它具有 scale
属性。到目前为止,我所做的是:
// The startPoint is the point of the first finger of the gesture, and the endPoint is the second finger.
// The scale value is from the UIPinchGestureRecognizer class
func handlePinch(startPoint: CGPoint, endPoint: CGPoint, scale: CGFloat) {
...
var castedShape = SomeShapeWithTwoPoints...
let transform = CGAffineTransform(scaleX: scale, y: scale)
castedShape.a = castedShape.a.applying(transform)
castedShape.b = castedShape.b.applying(transform)
...
}
但不幸的是,它的行为并不像我预期的那样(我会说计算出的点太大了,它把点放在了视图之外)。由于我不确定我哪里做错了,我的问题是如何根据捏合手势的比例值以正确的方式获取更新的
CGPoint
s?