在 SwiftUI 中,滚动视图内部 UI 视图的阴影会被滚动视图的大小切断吗?



更新Xcode11 beta3后,我发现ScrollView Inner View的阴影将被切断,但在Xcode11 beta2中可以。我只是使用底部填充来修复它,但我认为这不是一个很好的解决方案。还有其他解决方案可以解决问题吗?

ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 30) {
                    ForEach(courses) { item in
                        PresentationLink(destination: ContentView()) {
                            CourseView(
                                title: item.title,
                                image: item.image,
                                color: item.color,
                                shadowColor: item.shadowColor
                            )
                        }
                    }
                }
                .padding(.leading, 40)
                .padding(.bottom, 60)

Cousseview((具有阴影修饰符,定义的主体就像:

var body: some View {
        return VStack(alignment: .leading) {
            Text(title)
                .font(.title)
                .fontWeight(.bold)
                .color(.white)
                .padding(30)
                .lineLimit(4)
                .padding(.trailing, 50)
            Spacer()
            Image(image)
                .resizable()
                .renderingMode(.original)
                .aspectRatio(contentMode: .fit)
                .frame(width: 246, height: 150)
                .padding(.bottom, 30)
            }
            .background(color)
            .cornerRadius(30)
            .frame(width: 246, height: 360)
            .shadow(color: shadowColor, radius: 20, x:0, y: 20)
    }

我希望Cousseview((的影子可以显示正常,不要被ScrollView的界限切断。

在水平堆栈之后和之前尝试使用spacer((。这样,您的水平堆栈(HSTACK(将全部滚动视图。希望它有帮助

我有一个解决问题的问题。该解决方案是在下一个视图中使用偏移量,并将其重叠在ScrollView的顶部。在您的情况下,它看起来像这样:

ScrollView(.horizontal, showsIndicators: false) {
                HStack(spacing: 30) {
                    ForEach(courses) { item in
                        PresentationLink(destination: ContentView()) {
                            CourseView(
                                title: item.title,
                                image: item.image,
                                color: item.color,
                                shadowColor: item.shadowColor
                            )
                        }
                    }
                }
                .padding(.leading, 40)
                .padding(.bottom, 60)
}
SomeView().offset(x:0, y: -60) // 60 is your bottom padding so we offset by negative 60 to counter it.

最新更新