簡體   English   中英

如何禁用 SwiftUI ScrollView 剪輯

[英]How to disable SwiftUI ScrollView clipping

請參閱以下示例代碼:

ScrollView(.horizontal, showsIndicators: false) {
    HStack(spacing: 20) {
        ForEach(0 ..< 12) { index in
            Rectangle()
                .foregroundColor(.white)
                .frame(width: 100, height: 100, alignment: .center)
                .shadow(radius: 20)
        }
    }
}

此示例代碼將生成一個以Rectangle作為元素的水平ScrollView

但是,看起來 ScrollView 實際上會剪輯它的內容,因此頂部和底部的任何陰影都將被剪輯。

有沒有辦法通過滾動視圖禁用自動剪輯或其他方式來實現這一點?

陰影不會影響Rectangle的框架。 因此,嘗試為 Rectangle 添加填充,通過增加 Rectangle 的幀大小(包括陰影),陰影仍然可見。

ForEach(0 ..< 12) { index in
    Rectangle()
        .foregroundColor(.white)
        .frame(width: 100, height: 100, alignment: .center)
        .shadow(radius: 20)
        .padding(20) //<< Padding here for the radius
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM