gpt4 book ai didi

ios - 长按 NavigationView 只对左侧有效,不是所有 NavigationLink?

转载 作者:行者123 更新时间:2023-12-01 21:48:45 36 4
gpt4 key购买 nike

下面是一个 NavigationView, View 弹出到 Destination2当长按 NavigationLink 和 Destination1当通常点击它。但是图片中NavigationLink的右侧区域不能长按。

有谁知道原因?谢谢!

import SwiftUI

struct ContentView: View {

@State private var isLongPressed = false
@State var currentTag: Int?

let lyrics = ["OutNotWorkA", "OutNotWorkB", "OutNotWorkC"]

var body: some View {
NavigationView {

List {

ForEach(0..<lyrics.count) { index in
VStack{
HStack(alignment: .top) {
NavigationLink(destination: Group
{ if self.isLongPressed { Destination2() } else { Destination1() } }, tag: index, selection: self.$currentTag
) {
Text(self.lyrics[index])
}


}
}.simultaneousGesture(LongPressGesture().onEnded { _ in
print("Got Long Press")
self.currentTag = index
self.isLongPressed = true
})
.simultaneousGesture(TapGesture().onEnded{
print("Got Tap")
self.currentTag = index
self.isLongPressed = false
})
.onAppear(){
self.isLongPressed = false
}

}
}
}
}
}

struct Destination1: View {
var body: some View {
Text("Destination1")
}
}

struct Destination2: View {
var body: some View {
Text("Destination2")
}
}

enter image description here

最佳答案

Then how to handle the whole part?



在下面找到修复
VStack{
HStack(alignment: .top) {
NavigationLink(destination: Group
{ if self.isLongPressed { Destination2() } else { Destination1() } }, tag: index, selection: self.$currentTag
) {
Text(self.lyrics[index])
}


}
}
.contentShape(Rectangle()) // << here !!
.simultaneousGesture(LongPressGesture().onEnded { _ in

关于ios - 长按 NavigationView 只对左侧有效,不是所有 NavigationLink?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61865269/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com