小编Rob*_*mac的帖子

仅当标题被固定时才自定义节标题,否则不会(SwiftUI)

我的问题很简单:是否有任何方法可以仅在固定节时自定义节的标题,但如果未固定则保持其原样?

我试图将 .shadow 添加到部分的标题中,但我不希望它始终可见,但仅在开始向下滚动经过父 ScrollView 中的标题时(当标题被固定时)。

我主要寻找一个纯粹的 SwiftUI 解决方案,但我也愿意讨论其他解决方案。:)

struct WorkoutCardView: View {
    @Binding var workout: Workout
    @State var expandWorkout: Bool = false
    
    @Environment(\.colorScheme) var colorScheme
    
    var body: some View {
        LazyVStack(alignment: .leading, pinnedViews: .sectionHeaders) {
            Section {
                if expandWorkout {
                    WCExerciseSectionView(workout: $workout)
                }
            } header: {
                WCTitleSectionView(workout: $workout)
                    .background {
                        Color(uiColor: .systemBackground)
                        Color(uiColor: .systemFill)
                    }
                    .cornerRadius(10)
                    .shadow(color: colorScheme == .light ?
                            Color.black.opacity(expandWorkout ? 0.6 : 0) :
                                Color.white.opacity(expandWorkout ? 0.6 : 0), radius: 5, x: 0, y: 2)
                    .padding(.all, …
Run Code Online (Sandbox Code Playgroud)

header ios swift swiftui

5
推荐指数
1
解决办法
2667
查看次数

标签 统计

header ×1

ios ×1

swift ×1

swiftui ×1