Created
June 22, 2024 05:02
-
-
Save Koshimizu-Takehito/0efa70d63d2ca8c87565c05964597cb3 to your computer and use it in GitHub Desktop.
VisualEffect2
This file contains hidden or 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 { | |
var body: some View { | |
ScrollView(.vertical) { | |
ForEach(0..<1000) { i in | |
RoundedRectangle(cornerRadius: 24) | |
.fill(.blue) | |
.frame(height: 100) | |
.padding(.horizontal) | |
.visualEffect { content, proxy in | |
let y = proxy.frame(in: .global).origin.y | |
let offset = y > 60 ? 0 : -(y-60) | |
let scale = y > 60 ? 1 : min(max(((y-60)/1200 + 1), 0.4), 1) | |
let blurradius = y > 60 ? 0 : min(max(-(y-60)/100, 0), 4) | |
return content | |
.hueRotation(.degrees( y/10)) | |
.scaleEffect(x: scale, y: scale, anchor: .top) | |
.offset(y: offset - max(min(0.08 * offset * (1 - 1/exp(offset)), 30), 0)) | |
.opacity(y < -800 ? 0 : 1) | |
.blur(radius: blurradius) | |
} | |
} | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment