我的ScrollView的顶部及其子Image(img1)在下面。
我将图像稍微向下拖动,以便您可以看到它与ScrollView角的边缘重叠。
ios - 如何防止 subview 重叠其父级ScrollView?-LMLPHP
这是我的观点:

struct Match: View {
    @State var img1: Image? = nil
    @State var img2: Image? = nil
    @State var img3: Image? = nil
    @State var number: Text = Text("25")
    let storage = Storages()
    var body: some View {
        VStack {
            number.font(.system(size: 25))
                .foregroundColor(Color.white)
                .fontWeight(.bold)
            ScrollView(.vertical, showsIndicators: true) {
                ZStack(alignment: .bottomLeading){
                    img1?.resizable().scaledToFit()
                        Text("Text")
                            .font(.system(size: 30))
                            .fontWeight(.bold)
                            .foregroundColor(.white)
                            .multilineTextAlignment(.leading)
                            .padding(EdgeInsets(top: 0, leading: 35, bottom: 55, trailing: 0))

                        Text("500")
                            .font(.system(size: 30))
                            .fontWeight(.bold)
                            .foregroundColor(.white)
                            .multilineTextAlignment(.leading)
                            .padding(EdgeInsets(top: 0, leading: 35, bottom: 20, trailing: 0))
                }.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
                img2?.resizable().scaledToFit()
                img3?.resizable().scaledToFit()
            }.background(
                RoundedRectangle(cornerRadius: 15)
                    .foregroundColor(Color("LightBlack70%"))
            ).frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)

    }
    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
如何防止图像与ScrollView重叠? ScrollView具有cornerRadius: 15

最佳答案

尝试添加剪辑形状(因为它不是ScrollView,但是自定义添加的背景带有圆角),例如

ScrollView(.vertical, showsIndicators: true) {

 // .. content here

}.background(
    RoundedRectangle(cornerRadius: 15)
        .foregroundColor(Color("LightBlack70%"))
).clipShape(
    RoundedRectangle(cornerRadius: 15)
).frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)

关于ios - 如何防止 subview 重叠其父级ScrollView?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62774615/

10-16 14:43