Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created March 11, 2022 06:14
Show Gist options
  • Save chriseidhof/6f760bef5568b3ca2eaf962076fcbc92 to your computer and use it in GitHub Desktop.
Save chriseidhof/6f760bef5568b3ca2eaf962076fcbc92 to your computer and use it in GitHub Desktop.
import SwiftUI
let url = URL(string: "https://www.objc.io/images/books/thinking-in-swiftui/thinking-in-swiftui-hero-original_216a663.png")!
struct ContentView: View {
var image: some View {
AsyncImage(url: url, content: { image in
image
.resizable()
.aspectRatio( contentMode: .fit)
}, placeholder: {
Color.clear
})
.matchedGeometryEffect(id: "image", in: ns)
.onTapGesture {
withAnimation(.default) {
toggle.toggle()
}
}
}
@Namespace var ns
@State var toggle = false
var body: some View {
ZStack {
if toggle {
image
} else {
image
.padding(50)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
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