Home > AI > IOS > SwiftUI >

(Example) scroll rotate effect

struct ContentView: View {
    let colors: [Color] = [.red, .green, .blue, .orange, .pink, .purple, .yellow]

    var body: some View {
        GeometryReader { fullView in
            ScrollView(.vertical) {
                ForEach(0..<50) { index in
                    GeometryReader { geo in
                        Text("Row #\(index)")
                            .font(.title)
                            .frame(width: fullView.size.width)
                            .background(self.colors[index % 7])
                            .rotation3DEffect(.degrees(Double(geo.frame(in: .global).minY) / 5), axis: (x: 0, y: 1, z: 0))
                            .onAppear{
                                print(geo.frame(in: .global).minY)
                            }
                    }
                    .frame(height: 40)
                }
            }
            .onAppear {
                print(UIScreen.main.bounds.width)
                print(UIScreen.main.bounds.height)
                print(fullView.size.width)
                print(fullView.size.height)
                print(UIApplication.shared.windows.first?.safeAreaInsets.top ?? 0)
            }
        }
        
    }
}

Leave a Reply