Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGAffineTransformScale in Swift 3.0

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?

like image 637
Eric Avatar asked Apr 17 '17 18:04

Eric


2 Answers

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)
like image 186
kennytm Avatar answered Oct 23 '22 05:10

kennytm


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)
    ...
  }
like image 34
David S. Avatar answered Oct 23 '22 03:10

David S.