Swift 3.0 does not have a method called CGAffineTransformScale
.
func didPinchGesture(pinchRecognizer : UIPinchGestureRecognizer) {
if let view = pinchRecognizer.view {
view.transform = CGAffineTransformScale(view.transform,
recognizer.scale, recognizer.scale)
pinchRecognizer.scale = 1
}
}
scaleBy
does not autocomplete but added to CGAffineTransform
scaleBy
throws error, since scale
is not a property of CGAffineTransform anymore:
CGAffineTransform.scaledBy(view.transform, pinchRecognizer.scale, pinchRecognizer.scale)
.
What is the best way to configure the pinch gesture recognizer with Swift 3.0?
In 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)
You can use a scale transform in Swift 3 like this:
if let view = pinchRecognizer.view {
view.transform = CGAffineTransform(scaleX: recognizer.scale, y: recognizer.scale)
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With