13.2 C
Canberra
Thursday, November 14, 2024

ios – Picture show difficulty in SwiftUI


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)
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles