Skip to content

Instantly share code, notes, and snippets.

@1mash0
Last active August 20, 2023 03:42
Show Gist options
  • Save 1mash0/8f6b2d0ea6c43e5752bffb74b24dccf9 to your computer and use it in GitHub Desktop.
Save 1mash0/8f6b2d0ea6c43e5752bffb74b24dccf9 to your computer and use it in GitHub Desktop.
SwiftUI+GeometryReader (Make the center item larger)
import SwiftUI
struct ContentView: View {
let halfScreenWidth = UIScreen.main.bounds.width / 2
let magnification: CGFloat = 1.8
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
horizontalBalls
Spacer()
horizontalImages
Spacer()
horizontalCircleImages
Spacer()
}
}
var horizontalBalls: some View {
ScrollView(.horizontal, showsIndicators: true) {
HStack(spacing: 15) {
ForEach(0...100, id: \.self) { _ in
GeometryReader { geometry in
Circle()
.frame(width: 100, height: 100)
.frame(minHeight: geometry.size.height)
.foregroundColor(.red)
.scaleEffect(
max(1,
-abs(geometry.frame(in: .global).midX - self.halfScreenWidth) / self.halfScreenWidth * self.magnification + self.magnification
)
)
}
.frame(width: 100, height: self.magnification * 100)
.padding()
}
}
}
}
var horizontalImages: some View {
ScrollView(.horizontal, showsIndicators: true) {
HStack(spacing: 15) {
ForEach(0...100, id: \.self) { _ in
GeometryReader { geometry in
Image("turtlerock")
.resizable()
.frame(width: 100, height: 100)
.frame(minHeight: geometry.size.height)
.foregroundColor(.red)
.scaleEffect(
max(1,
-abs(geometry.frame(in: .global).midX - self.halfScreenWidth) / self.halfScreenWidth * self.magnification + self.magnification
)
)
}
.frame(width: 100, height: self.magnification * 100)
.padding()
}
}
}
}
var horizontalCircleImages: some View {
ScrollView(.horizontal, showsIndicators: true) {
HStack(spacing: 15) {
ForEach(0...100, id: \.self) { _ in
GeometryReader { geometry in
Image("turtlerock")
.resizable()
.clipShape(Circle())
.overlay {
Circle().stroke(.white, lineWidth: 2)
}
.shadow(radius: 7)
.frame(width: 100, height: 100)
.frame(minHeight: geometry.size.height)
.foregroundColor(.red)
.scaleEffect(
max(1,
-abs(geometry.frame(in: .global).midX - self.halfScreenWidth) / self.halfScreenWidth * self.magnification + self.magnification
)
)
}
.frame(width: 100, height: self.magnification * 100)
.padding()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment