Skip to content

Instantly share code, notes, and snippets.

@wb-towa
Forked from robb/image-expansion.swift
Created May 16, 2022 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wb-towa/d45d289790bc01c887becfc343a64c43 to your computer and use it in GitHub Desktop.
Save wb-towa/d45d289790bc01c887becfc343a64c43 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var pictureExpanded = false
var body: some View {
VStack(alignment: .leading, spacing: 20.0) {
Text("Once upon a time there was a turtle named George who made friends with a giraffe at the local water park and then they went on lots of adventures together.")
Button {
withAnimation {
pictureExpanded.toggle()
}
} label: {
Text("Tap to \(pictureExpanded ? "hide" : "see") a pretty picture")
}
Image("cat")
.resizable()
.aspectRatio(contentMode: .fit)
.fixedSize(horizontal: false, vertical: true)
.frame(height: pictureExpanded ? 311 : 0.0)
.clipped()
.frame(height: pictureExpanded ? 311 : 0.0)
.contentShape(Rectangle())
Text("The giraffe's name was Leonard, and together George and Leonard became the best of friends and did all sorts of cool things together like climbing a mountain.")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment