0

I am using part of the following repo: https://github.com/pd95/CS193p-EmojiArt Have modified some of the code, as I am using images instead of Emojies, but the size part I can't figure out.

The Emojies use size with a same number for width and height, but with my images, I use a different for the width and height (all images have the same width and height).

When I zoom the page, the images do not resize.

From the mentioned repo, I haven't changed the size part and zoom part.

Somebody has an idea how I can fix that?

Updating with example code

Size is set as int:

var size: Int

There is a scaleInstruments function:

func scaleInstrument(_ instrument: StageManager.Instrument, by scale: CGFloat) {
    if let index = stageManager.instruments.firstIndex(matching: instrument) {
        stageManager.instruments[index].size = Int((CGFloat(stageManager.instruments[index].size) * scale).rounded(.toNearestOrEven))
    }
}

And the zoomScale / zoomGesture functions:

@GestureState private var gestureZoomScale: CGFloat = 1.0

private var zoomScale: CGFloat {
    document.steadyStateZoomScale * (hasSelection ? 1 : gestureZoomScale)
}

private func zoomScale(for instrument: StageManager.Instrument) -> CGFloat {
    if isInstrumentSelected(instrument) {
        return document.steadyStateZoomScale * gestureZoomScale
    }
    else {
        return zoomScale
    }
}

private func zoomGesture() -> some Gesture {
    MagnificationGesture()
        .updating($gestureZoomScale, body: { (latestGestureScale, gestureZoomScale, transaction) in
            gestureZoomScale = latestGestureScale
        })
        .onEnded { finalGestureScale in
            if self.hasSelection {
                self.selectedInstrumentIDs.forEach { (instrumentId) in
                    if let instrument = self.document.instruments.first(where: {$0.id == instrumentId }) {
                        self.document.scaleInstrument(instrument, by: finalGestureScale)
                    }
                }
            }
            else {
                self.document.steadyStateZoomScale *= finalGestureScale
            }
        }
}

Hope this sufficient to explain the issue I have.

udarts
  • 745
  • 1
  • 8
  • 23

1 Answers1

0

I managed to do this, using the following code change:

From:

.frame(width: 140, height: 70)

To:

.frame(width: 140 * self.zoomScale(for: instrument), height: 70 * self.zoomScale(for: instrument))

Now the images will resize according the zoom.

udarts
  • 745
  • 1
  • 8
  • 23