0si43 / PiecesOfPaper

Note app focused on quick sketch by Apple Pencil
https://apps.apple.com/jp/app/like-a-paper/id1511690088#?platform=ipad
MIT License
62 stars 8 forks source link

Add pinch in/out action #49

Closed 0si43 closed 2 years ago

0si43 commented 3 years ago
0si43 commented 2 years ago

IMG_0950 IMG_0951

0si43 commented 2 years ago

I had used MagnificationGesture like this

struct Canvas: View {
    @GestureState var magnifyBy = 1.0

    var magnification: some Gesture {
        MagnificationGesture()
            .updating($magnifyBy) { currentState, gestureState, _ in
                gestureState = currentState
            }
    }

    var tap: some Gesture {
        // …
    }

    var body: some View {
        PKCanvasViewWrapper(canvasView: $viewModel.canvasView)
            .gesture(tap)
            .scaleEffect(magnifyBy)
            .gesture(magnification)

But, this result was not an expected behavior

https://user-images.githubusercontent.com/45909001/155639035-f41226a1-9f01-4a38-8f6f-48ad52875538.mov

Hopefully, zoom level stay after leaving fingers. A center point is touch point

0si43 commented 2 years ago

I found the delegate method named viewForZooming(in:) . It's enabled pint-in/out action with setting minimum/maximumZoomScale!

https://user-images.githubusercontent.com/45909001/155643224-9f39f767-dca0-4c13-a5fa-349779255569.mov

Yes, this is perfect

0si43 commented 2 years ago

I set minimum value, it was enable to pinch out. It was a bit of convenience……maybe…… But it will make difficult to back normal(x1.0) zoom scale.

I decided not to set minimum scale(and default value is 1.0). If user want to back normal scale, they just repeatedly pinch out.