Created
March 15, 2024 22:00
-
-
Save heestand-xyz/49cd9810eab73eaf0fb6a2985a3854d1 to your computer and use it in GitHub Desktop.
SwiftUI Content Mode Animation
This file contains 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 | |
struct ContentView: View { | |
@State private var contentMode: ContentMode = .fit | |
var body: some View { | |
ZStack { | |
Image("Kite") | |
.resizable() | |
.aspectRatio(contentMode: contentMode) | |
.animation(.easeInOut, value: contentMode) | |
.ignoresSafeArea() | |
Picker(selection: $contentMode) { | |
Text("Fit") | |
.tag(ContentMode.fit) | |
Text("Fill") | |
.tag(ContentMode.fill) | |
} label: { | |
Text("Content Mode") | |
} | |
.pickerStyle(.segmented) | |
.frame(width: 100) | |
.padding(5) | |
.background { | |
RoundedRectangle(cornerRadius: 10) | |
.foregroundStyle(.ultraThinMaterial) | |
} | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screen.Recording.2024-03-16.at.6.59.47.mov