Imagine a simple scrollview that contains a content view with an image in it which should be centered vertically if height is smaller than the scrollview's height.
If the image exceeds the height of the scrollview the scrollview should allow scrolling to display the complete image.
Additionally if the image is narrower than its container it should be centered horizontally.
When being scaled down the image should always retain its intrinsic aspectRatio.
These are the requirements
How would you do that in SwiftUI?
What are the problems that need to be tackled here?
- content views of scrollviews are not automatically centered, they are aligned top-leading
- resizable images always take all the space they get, even if intrinsically smaller than its frames (thus they scale up, which is nasty)
- the aspect ratio of the image needs to be as it was originally
- if the image gets taller than the scrollview itself the content needs to be scrollable to reveal the whole image
What should not be part of the solution:
- pinch to scale
Similar issues on Stackoverflow (not really solving the issue):