我正在尝试创建一个列表,其中的行在鼠标经过时会更改背景颜色。但使用当前代码,所有行都会在悬停时突出显示。
struct ContentView: View {
@State private var overText = false
var body: some View {
List{
ForEach(0 ..< 3){ item in
Row(text: "hhaha")
.background(Color(overText ? .systemBlue : .clear))
.onHover(perform: { hovering in
overText.toggle()
})
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是当前结果
这就是我想要实现的目标
在 iOS 中,可以通过长按或点击来显示上下文菜单。目前,以下代码在长按时显示上下文菜单,如何在轻按时显示菜单?
let interaction = UIContextMenuInteraction(delegate: self)
tagBtn.addInteraction(interaction)
func contextMenuInteraction(_ interaction: UIContextMenuInteraction,
configurationForMenuAtLocation location: CGPoint)
-> UIContextMenuConfiguration? {
let favorite = UIAction(title: "Favorite",
image: UIImage(systemName: "heart.fill")) { _ in
// Perform action
}
let share = UIAction(title: "Share",
image: UIImage(systemName: "square.and.arrow.up.fill")) { action in
// Perform action
}
let delete = UIAction(title: "Delete",
image: UIImage(systemName: "trash.fill"),
attributes: [.destructive]) { action in
// Perform action
}
return UIContextMenuConfiguration(identifier: nil,
previewProvider: nil) { _ in
UIMenu(title: "Actions", children: [favorite, share, delete]) …Run Code Online (Sandbox Code Playgroud)