ios - 如何防止子视图与其父 ScrollView 重叠?
问题描述
我的顶部ScrollView
和它的孩子Image
( img1
) 在下面。
我将图像稍微向下拖动,以便您可以看到它与ScrollView
角落的边缘重叠。
这是我的观点:
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 - Swift UITextField 和模拟器
- .net - 连接到 IIS 并找到 .NET DLL
- python - Python多线程正在django中混合不同请求的数据
- algorithm - 这段代码的时间复杂度是多少?
- django - 已解决:Django - WSGI 脚本无法作为 Python 模块加载
- sql - PostgreSQL 不会删除重复项
- c++ - C++ 等价于 Java 的匿名类
- python - 我试图找到一种方法来完成这项工作,它试图计算一个短语在逐行文本文件中出现的次数
- javascript - 在连接时更新 Firebase 中的用户配置文件
- jmeter - 如何在 JMeter 5.2.1 中参数化线程数