Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SwiftUI make image bigger on tap

I’m trying to make an app and i want to make the image bigger when tapped. And when tapped outside the picture it would go back to normal. How is that possible? Found out there is .onTapGesture() but can’t seem to find how to make the image bigger with that.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Simply use .scaleEffect with a condition to scale up and down the view e.g

import SwiftUI

struct ContentView: View {
    @State private var selected: Bool = false

    var body: some View {
        VStack {
            Image(systemName: "camera.fill")
                .resizable()
                .onTapGesture {
                    selected.toggle()
                }
                .scaleEffect(self.selected ? 1.5 : 1)
        }
        .frame(width: 100, height: 100, alignment: .center)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading