Swift 支持隐藏滚动条上的导航栏navigationController?.hidesBarsOnSwipe = true
需要明确的是,我希望它只隐藏在滚动条上,所以.navigationBarHidden(true)还不够。
我尝试按照 Stackoverflow 答案中的描述访问 NavigationController (我添加了nc.hidesBarsOnSwipe = true),但在编译时,它不起作用。
SwiftUI 支持吗?
NavigationView似乎仍然相对有问题。例如,默认情况下 aScrollView将忽略标题区域并仅在其下方滚动。
在我看来,你可以通过使用displayMode: .inline和StackNavigationViewStyle()来实现这一点。
struct ContentView: View {
var body: some View {
NavigationView {
ScrollView {
ForEach(0...20, id: \.self) { count in
(count % 2 == 0 ? Color.red : Color.blue)
.frame(height: 44.0)
}
}
.background(NavigationConfigurator { nc in // NavigationConfigurator is from the OP's post: https://stackoverflow.com/a/58427754/7834914
nc.hidesBarsOnSwipe = true
})
.navigationBarTitle("Hello World", displayMode: .inline)
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9496 次 |
| 最近记录: |