In this post we go over how to convert the entire layout of a GeometryReader-driven List view with only 15 character changes!
[cc lang=”swift”] //// ContentView.swift
// GeometryReaderFun
//
// Created by Laurie Gray on 25/09/2019.
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
VStack {
Text(“Menu”)
.font(.largeTitle)
.fontWeight(.bold)
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(Range(1…4)) { iteration in
GeometryReader { proxy in
Image(“food\(iteration)”)
.resizable()
.scaledToFill()
.frame(width: 200, height: 200)
.clipped()
.padding()
.shadow(radius: 3)
.background(Color.white)
.shadow(radius: 3)
.rotation3DEffect(Angle(degrees: Double(proxy.frame(in: .global).midX) / 20), axis: (x: 100, y: -100, z: 100))
}
.frame(width: 300, height: 275)
}
}
}
}
Spacer()
}
.background(Image(“bg”).resizable().scaledToFill())
.edgesIgnoringSafeArea(.all)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}