-
Notifications
You must be signed in to change notification settings - Fork 42
/
PhotoZoom.swift
49 lines (43 loc) · 1.27 KB
/
PhotoZoom.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// PhotoZoom.swift
// SwiftUISpringAnimations
//
// Created by amos.gyamfi@getstream.io on 25.2.2022.
//
// A simple photozoom
import SwiftUI
struct PhotoZoom: View {
@State private var zoomed = false
@Namespace private var smooth
var body: some View {
ZStack {
if !zoomed {
Image("iceland4")
.resizable()
.matchedGeometryEffect(id: "morph", in: smooth)
.aspectRatio(contentMode: .fit)
} else {
ZStack {
Image("iceland4")
.resizable()
.matchedGeometryEffect(id: "morph", in: smooth)
.ignoresSafeArea()
Text("Iceland")
.font(.largeTitle)
.textCase(.uppercase)
}
}
} // Both images
.onTapGesture{
withAnimation(.interpolatingSpring(mass: 1, stiffness: 170, damping: 15, initialVelocity: 0)){
zoomed.toggle()
}
}
}
}
struct PhotoZoom_Previews: PreviewProvider {
static var previews: some View {
PhotoZoom()
.preferredColorScheme(.dark)
}
}