SwiftUI NavigationBar not disappearing while scrolling

前端 未结 2 777
南笙
南笙 2021-01-15 15:17

I want to hide my NavigationBar while scrolling, actually It must hide automatically but when I tried with multiple views It doesn\'t work. Also, It works when

相关标签:
2条回答
  • 2021-01-15 15:49

    Based on Asperi's solution, I wanted to have the SearchBar and StatusView always visible, i.e. it should stop scrolling after the title has disappeard. You can achieve this with a section header like shown below (just a rough sketch):

    NavigationView {
        List {
            Section(header: {
                VStack {
                    SearchBar...
                    StatusView....
                }
            }) {
                ForEach...
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-15 15:57

    Just idea, scratchy... try to put your custom views inside List as below (I know it will work, but I'm not sure if autohiding will work)

    NavigationView {
      List {
          SearchBar(searchText: $viewModel.searchText)
          StatusView(status: $viewModel.status)
          Divider()
    
          ForEach (0...viewModel.characters.results.count, id: \.self) { index in
          ...
    
    0 讨论(0)
提交回复
热议问题