bla*_*ops 24 navigationview swiftui
有没有办法隐藏自动添加的导航链接视图右侧的箭头?
我想使用 NavigationView -> List -> HStack -> NavigationLink_1 - NavigationLink_2 显示图像网格
Vla*_*ics 29
它对我有用的方式:
List {
ForEach(elements) { element in
ZStack {
CustomView(element: element)
NavigationLink(destination: DestinationView()) {
EmptyView()
}.buttonStyle(PlainButtonStyle())
}
}
}
Run Code Online (Sandbox Code Playgroud)
Jag*_*eon 12
我完成了这个
NavigationLink(destination: DestinationView()) {
EmptyView()
}
.frame(width: 0, height: 0)
.hidden()
Run Code Online (Sandbox Code Playgroud)
唯一对我有帮助的是添加.opacity(0)到 NavigationLink,如下所示:
List {
ForEach(elements) { element in
ZStack {
CustomView(element: element)
NavigationLink(destination: DestinationView()),
label: {}).opacity(0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
List {
ForEach(elements) { element in
ZStack {
CustomView(element: element)
NavigationLink(destination: DestinationView()) {
EmptyView()
}.opacity(0.0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我发现的最简单的方法是将导航放在.background带有opacity零的修饰符中:
List {
Text("The cell")
.background( NavigationLink("", destination: Text("The detail view controller")).opacity(0) )
}
Run Code Online (Sandbox Code Playgroud)
使用此解决方案,您不会失去单元格的动态高度功能。
小智 5
我最近也遇到了这个问题,我想我已经通过使用导航链接的自定义视图找到了解决方案(它对我有用):
struct CustomNavigationLink<D: View, L: View>: View {
@ViewBuilder var destination: () -> D
@ViewBuilder var label: () -> L
@State private var isActive = false
var body: some View {
Button {
withAnimation {
isActive = true
}
} label: {
label()
}
.onAppear {
isActive = false
}
.overlay {
NavigationLink(isActive: $isActive) {
destination()
} label: {
EmptyView()
}
.opacity(0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
你这样使用:
CustomNavigationLink {
SomeViewHere()
} label: {
Text("hello world")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13107 次 |
| 最近记录: |