File tree 3 files changed +62
-1
lines changed
SwiftUIPlayground.xcodeproj/project.xcworkspace/xcuserdata/tahatesser.xcuserdatad
3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -145,5 +145,11 @@ public let samples: [String: AnyView] = [
145
145
" ViewThatFits " : AnyView ( ViewThatFitsSample ( ) ) ,
146
146
]
147
147
) ) ,
148
-
148
+ " Animations " : AnyView ( SamplesList (
149
+ title: " Animations " , samples:
150
+ [
151
+ // https://developer.apple.com/documentation/swiftui/view/matchedgeometryeffect(id:in:properties:anchor:issource:)
152
+ " matchedgeometryeffect " : AnyView ( MatchedGeometryEffectSample ( ) ) ,
153
+ ]
154
+ ) ) ,
149
155
]
Original file line number Diff line number Diff line change
1
+ //
2
+ // MatchedGeometryEffectSample.swift
3
+ // SwiftUIPlayground
4
+ //
5
+ // Created by Taha Tesser on 07.10.2024.
6
+ //
7
+
8
+ import SwiftUI
9
+
10
+ struct MatchedGeometryEffectSample : View {
11
+ @Namespace private var animation
12
+ @State private var isExpanded : Bool = false
13
+
14
+ var body : some View {
15
+ ZStack {
16
+ if isExpanded {
17
+ ZStack {
18
+ RoundedRectangle ( cornerRadius: 10 )
19
+ . fill ( . black)
20
+ . clipShape ( RoundedRectangle ( cornerRadius: 16 ) )
21
+ Image ( systemName: " rainbow " )
22
+ . symbolRenderingMode ( . multicolor)
23
+ . resizable ( )
24
+ . scaledToFit ( )
25
+ . padding ( )
26
+ . matchedGeometryEffect ( id: " park " , in: animation)
27
+
28
+ }
29
+ } else {
30
+ ZStack {
31
+ RoundedRectangle ( cornerRadius: 10 )
32
+ . fill ( . black)
33
+ . frame ( height: 100 )
34
+ . clipShape ( RoundedRectangle ( cornerRadius: 16 ) )
35
+ Image ( systemName: " rainbow " )
36
+ . symbolRenderingMode ( . multicolor)
37
+ . resizable ( )
38
+ . scaledToFit ( )
39
+ . frame ( height: 80 )
40
+ . matchedGeometryEffect ( id: " park " , in: animation)
41
+ }
42
+ . padding ( )
43
+ }
44
+ }
45
+ . onTapGesture {
46
+ withAnimation ( . spring( ) ) {
47
+ isExpanded. toggle ( )
48
+ }
49
+ }
50
+ . ignoresSafeArea ( ) }
51
+ }
52
+
53
+ #Preview {
54
+ MatchedGeometryEffectSample ( )
55
+ }
You can’t perform that action at this time.
0 commit comments