如何崩溃和淡入Swiftui

问题描述 投票:0回答:1

启用用于不透明度的单独状态变量并独立进行动画,您可以使不透明度取决于
headerOffset
swiftui header
1个回答
0
投票

// ScrollToHideView // @State private var opacity = 1.0

.safeAreaInset(edge: .top, spacing: 0) {
    HeaderView()
        .padding(.bottom, 16)
        .frame(height: headerHeight, alignment: .bottom)
        .background(.blue)
        .opacity(1.0 - min(1.0, max(0.0, headerOffset / headerHeight))) // 👈 here
        .offset(y: -headerOffset)
}

// animating opacity
// withAnimation(.easeIn(duration: 2)) {
//     if self.isScrollingUp {
//         opacity = 0
//     } else {
//         opacity = 1
//     }
// }
	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.