I’ve an Picture
view that shows photographs with aspectRatio .match
in the midst of the display (different parts will show above & beneath photographs). Then, a scaling impact is utilized to them. This works nicely for many of the photographs which have wider dimensions however one of many photographs seen right here shows with gaps from the sides of the display when run on an iPhone 16 simulator resulting in an unsightly scaling impact. My guess is that I would need to detect if a picture to be proven suits the display width and if not, resize it earlier than show. Would this be the one method to repair it? Please advise.
struct FancyViewer: View {
non-public let imageName = "dragon"
non-public let animDuration = 5.0
@State non-public var imageScale: CGFloat = 1.0
var physique: some View {
GeometryReader { proxy in
VStack {
Spacer()
Picture(imageName)
.resizable()
.aspectRatio(contentMode: .match)
.body(width: proxy.measurement.width, top: proxy.measurement.width * 1.5)
.scaleEffect(imageScale)
.animation(.linear(length: animDuration), worth: imageScale)
.clipped()
Spacer()
}
}
.body(maxWidth: .infinity, maxHeight: .infinity)
.background {
Picture(imageName)
.resizable()
.scaledToFill()
.foregroundStyle(.thinMaterial)
.overlay {
Shade.clear
.background(.ultraThinMaterial)
}
.ignoresSafeArea()
}
.onAppear {
imageScale = CGFloat.random(in: 1.0...1.3)
}
}
}