//
// test4Scroll.swift
// Music
//
// Created by QIAEN on 2025/1/15.
//
import SwiftUI
struct test4Scroll: View {
let safeArea: EdgeInsets
let size: CGSize
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 10) {
ImageView()
VStack(spacing: 10) {
Text("Popular")
.fontWeight(.heavy)
.foregroundStyle(.black)
Text("When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.When using NSNumberFormatter, you need to handle the situation where the string(from:) method may return nil, especially when dealing with different language environments and localization. When using the Decimal type, you need to import the Foundation framework and pay attention to the various parameter settings of NSDecimalNumberHandler to ensure correct rounding and precision control.")
.font(.system(size: 20))
.frame(width: 368, alignment: .leading)
.offset(y: -70)
.padding(15)
}
}
}
}
@ViewBuilder
func ImageView() -> some View {
let height = size.height
GeometryReader{proxy in
let size = proxy.size
let minY = proxy.frame(in: .named("SCROLL")).minY
let progress = minY / (height * (minY > 0 ? 0.5 : 0.8))
Image("avatar4")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: size.width, height: size.height + (minY > 0 ? minY : 0))
.clipped()
.overlay(content: {
ZStack(alignment: .bottom) {
Rectangle()
.fill(.linearGradient(colors: (0...5).map {
Color.black.opacity(Double($0) * 0.2 - progress)
}, startPoint: .top, endPoint: .bottom))
VStack(spacing: 0) {
Text("Chocolate\nCake Recipe")
.font(.system(size: 45))
.fontWeight(.bold)
.multilineTextAlignment(.center)
Text("10K Monthly Viewers")
.font(.caption)
.fontWeight(.bold)
.foregroundStyle(.gray)
.padding(.top, 15)
}
.opacity(1 + (progress > 0 ? -progress : progress))
.padding(.bottom, 55)
.offset(y: minY < 0 ? minY : 0)
}
})
.offset(y: -minY)
}
.frame(height: height + safeArea.top)
}
}
Preview {
GeometryReader {
let safeArea = $0.safeAreaInsets
let size = $0.size
test4Scroll(safeArea: safeArea, size: size)
.ignoresSafeArea(.container, edges: .top)
.preferredColorScheme(.dark)
}
}