Swift 3.0 中的 CGAffineTransformScale
CGAffineTransformScale in Swift 3.0
Swift 3.0 没有名为 CGAffineTransformScale
的方法。
func didPinchGesture(pinchRecognizer : UIPinchGestureRecognizer) {
if let view = pinchRecognizer.view {
view.transform = CGAffineTransformScale(view.transform,
recognizer.scale, recognizer.scale)
pinchRecognizer.scale = 1
}
}
scaleBy
不会自动完成但添加到 CGAffineTransform
scaleBy
会抛出错误,因为 scale
不再是 CGAffineTransform 的 属性:
CGAffineTransform.scaledBy(view.transform, pinchRecognizer.scale, pinchRecognizer.scale)
.
使用 Swift 3.0 配置捏合手势识别器的最佳方法是什么?
在Swift, CGAffineTransformScale
is imported as an instance method on the CGAffineTransform
struct, called scaledBy(x:y:)
:
view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale)
您可以像这样在 Swift 3 中使用缩放变换:
if let view = pinchRecognizer.view {
view.transform = CGAffineTransform(scaleX: recognizer.scale, y: recognizer.scale)
...
}
Swift 3.0 没有名为 CGAffineTransformScale
的方法。
func didPinchGesture(pinchRecognizer : UIPinchGestureRecognizer) {
if let view = pinchRecognizer.view {
view.transform = CGAffineTransformScale(view.transform,
recognizer.scale, recognizer.scale)
pinchRecognizer.scale = 1
}
}
scaleBy
不会自动完成但添加到 CGAffineTransform
scaleBy
会抛出错误,因为 scale
不再是 CGAffineTransform 的 属性:
CGAffineTransform.scaledBy(view.transform, pinchRecognizer.scale, pinchRecognizer.scale)
.
使用 Swift 3.0 配置捏合手势识别器的最佳方法是什么?
在Swift, CGAffineTransformScale
is imported as an instance method on the CGAffineTransform
struct, called scaledBy(x:y:)
:
view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale)
您可以像这样在 Swift 3 中使用缩放变换:
if let view = pinchRecognizer.view {
view.transform = CGAffineTransform(scaleX: recognizer.scale, y: recognizer.scale)
...
}