0

I have a drawing app that uses UIBezierpaths (vectors) and I'm trying to create a function that allows me to zoom around the canvas/UIView like other drawing apps do. I do not want to enlarge individual bezierpaths, I already know how to do that. I want a pinch to zoom functionality like safari that zooms the canvas/view.

If I use the following code:

self.transform = CGAffineTransform(scaleX: 2, y: 2)

This: enter image description here

Turns into this, which you'll notice is quite blurry/not smooth like vectors are supposed to be: enter image description here

But I want it to look something like this, which is what would happen on another drawing appenter image description here

I understand this question may have a complicated answer, but I'm struggling to find that answer by myself.

  • 1
    If you want to implement vector zooming, you should recalculate the points yourself. `CGAffineTransform` is not vector-based. – Tamás Sengel Aug 04 '17 at 14:27
  • CGaffinetransform does enlarge uibezierpaths correctly, but I want to transform the view –  Aug 04 '17 at 14:52

2 Answers2

0

I have made a drawing app that was able to zoom in. I didn't remember How I managed to handle this. But I think you should definitely use UIScrollView to manage the zooming / dragging part.
UIImageView pinch zoom swift

You will be able to pinch to zoom, drag etc for almost free. And It will not be pixelated I think

LastMove
  • 2,482
  • 1
  • 15
  • 25
  • Thanks for this. I was playing with this earlier with no success assuming this wasn't the solution, but will keep trying now you've informed me it probably is the solution –  Aug 04 '17 at 15:00
0

Add a UIPinchGestureRecognizer and UIPanGestureRecognizer to your drawing view. Then handle the delegate events from them to update your scale and offset. You then finally use resulting scale and offset to redraw (by calling setNeedsDisplay() typically).

I can tell you from experience that these calculations are a bit tricky but doable.

meaning-matters
  • 21,929
  • 10
  • 82
  • 142