Created
March 11, 2022 06:14
-
-
Save chriseidhof/6f760bef5568b3ca2eaf962076fcbc92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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