Skip to content

Instantly share code, notes, and snippets.

@heestand-xyz
Created March 15, 2024 22:00
Show Gist options
  • Save heestand-xyz/49cd9810eab73eaf0fb6a2985a3854d1 to your computer and use it in GitHub Desktop.
Save heestand-xyz/49cd9810eab73eaf0fb6a2985a3854d1 to your computer and use it in GitHub Desktop.
SwiftUI Content Mode Animation
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()
}
@heestand-xyz
Copy link
Author

Screen.Recording.2024-03-16.at.6.59.47.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment