- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的应用程序中有一个 View ,它显示了一个用于显示信息的自定义单元格数组的 ForEach,但我注意到很难在这些单元格的顶部滚动。我注意到如果我删除 .gesture(LongPressGesture()),它工作得很好,但我想保留它。有没有其他方法可以解决这个问题或替代 .gesture(LongPressGesture())?
这是我的代码:
struct refrigeItem: Identifiable, Hashable {
var id = UUID()
var icon: String
var title: String
var daysLeft: Int
}
struct RefrigeratorItemCell: View {
var icon: String
var title: String
var lastsUntil: Int
var body: some View {
HStack {
Text(icon)
.font(.largeTitle)
.padding(.leading, 8)
VStack {
HStack {
Text(title)
.font(.custom("SF Pro Text", size: 16))
.multilineTextAlignment(.leading)
Spacer()
}
HStack {
//TODO: fix this
Text("lasts for \(self.lastsUntil) days")
.font(.custom("SF Compact Display", size: 16))
.foregroundColor(.gray)
.multilineTextAlignment(.leading)
Spacer()
}
}
Spacer()
}
.padding()
.background(Rectangle().cornerRadius(16).padding(.horizontal)
.foregroundColor(.gray)
)
.padding(.bottom)
}
}
struct ContentView: View {
@State var displayPreview = [refrigeItem(icon: "🥚", title: "eggs", daysLeft: 5), refrigeItem(icon: "🥐", title: "croissant", daysLeft: 6)]
var body: some View{
NavigationView {
GeometryReader { geo in
VStack {
ScrollView(.vertical, showsIndicators: true, content: {
VStack {
ForEach(self.displayPreview, id: \.self){item in
RefrigeratorItemCell(icon: item.icon, title: item.title, lastsUntil: item.daysLeft)
.gesture(LongPressGesture()
.onEnded({ i in
print("long pressed")
}))
}
}
})
}
}
}
}
}
最佳答案
更新您的 RefrigeratorItemCell
在添加长按手势之前添加 onTapGesture:
RefrigeratorItemCell(icon: item.icon, title: item.title, lastsUntil: item.daysLeft)
.onTapGesture {}
.gesture(LongPressGesture()
.onEnded({ i in
print("long pressed")
}))
关于SwiftUI - 很难在自定义 View 之上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62052417/
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
我有一个带有输入字段的表单,使用javascript,当用户输入超过2个字符时,它会在第一个输入字段下方创建相同的输入字段。其代码是: Optie 1: 1 && treated[this.na
这是我的: char userInput; int position; vector userVector(7); vector someVector(7,1); cin >> userInput;
尝试使用 typescript 和 redux 构建一个简单的 react crud 应用程序并遇到以下问题。我有一个具有指定签名的函数,它将一个人对象作为参数,如此处所示。 export defau
哦,我多么希望 TCP 像 UDP 一样基于数据包! [查看评论] 但是,唉,事实并非如此,所以我正在尝试实现我自己的数据包层。这是到目前为止的事件链(忽略写入数据包) 哦,我的数据包结构非常简单:两
我想在我的页面底部放置一个包含不同数量图片的栏,这些图片(如果比页面宽)可以左右滚动。 页面宽度在变化,我希望 Pane 的宽度为 100%。 我试图通过让中间的 div 溢出并使用 jquery.a
我曾尝试在工作时将我的 Rails 应用程序 bundle 到我的 Mac 上。在家里它运行良好,我之前已经设法自己解决了它,但这次无论我尝试什么似乎都无法解决它。 我在运行 bundle/bundl
所以我有一个旧的网络表单站点,并且正在努力使其更易于维护。把它扔掉并重写它不是一种选择。 IoC 显然是它首先得到的东西之一,但这给我留下了服务定位器模式和糟糕的品味,并且想知道它是否可以做得更好。
我是一名优秀的程序员,十分优秀!