![](/img/trans.png)
[英]Can I round the corners of an HStack's background without clipping the content inside of it?
[英]How can I clip/mask HStack content to behave like a ScrollView where content is shown inside HStack?
我有一個自定義 TabView(Snap Carousel),我可以在其中滾動內容並捕捉到 TabView 內容。 內容基本上是寬度比 TabView 大 x 倍的 HStack,其中 x 也是頁面數。 我得到了所需的滾動行為,但是當我剪輯 MenuTabView 時,我丟失了可見區域之外的內容,滾動時它是空的。
HStack(spacing : 0) {
Image("image1")
.aspectRatio(2.8, contentMode: .fit)
.frame(width: proxy.size.width)
Image("image2")
.aspectRatio(2.8, contentMode: .fit)
.frame(width: proxy.size.width)
}
.frame(maxWidth: proxy.size.width, alignment: .leading)
.clipped()
代理是 GeometryProxy。
struct MenuTabView<Content: View> : View {
var body: some View {
GeometryReader { proxy in
ZStack {
content()
.offset(x: (CGFloat(index) * -proxy.size.width) + self.offset)
.gesture(
DragGesture()
........
}
} }
第二個圖像是第二頁,當我使用 .clipped() 進行剪輯時,它會滾動但不可見。 如何創建類似於 ScrollView 的行為
嘗試在 .offset 運算符之后移動 .frame(maxWidth: proxy.size.width, alignment: .leading) .clipped()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.