簡體   English   中英

如何在SwiftUI中向上滾動時隱藏導航欄?

[英]how to hide navigation bar while scrolling up in SwiftUI?

我已經實現了 scrollview ,它工作正常但是當我開始向上滾動它時我得到導航視圖並且一旦我停止滾動它就會隱藏。

有什么方法可以在滾動時刪除它或不顯示它。 基本上我不想要那個屏幕的導航視圖

我嘗試了以下方法但沒有用。

NavigationView  {
    ScrollView(viewmodel: self.viewmodel)
        .onAppear{
            self.viewmodel.abc()
        }
        .navigationBarHidden(true)
        .edgesIgnoringSafeArea([.top, .bottom])
}

滾動視圖在下面

struct ScrollView :UIViewRepresentable{
    func makeCoordinator() -> Coordinator {
        return ScrollView.Coordinator(parent1: self)
    }
    
    @ObservedObject var viewmodel : Viewmodel
    
    func makeUIView(context: Context) -> UIScrollView {
        let view  = UIScrollView()
        let childView = UIHostingController(rootView: PlayerView(viewmodel: self.viewmodel))
        childView.view.frame = CGRect(x: 0, y: 0, width: Screen.maxWidth, height: Screen.maxHeight*CGFloat(viewmodel.player.count))
        
        view.contentSize = CGSize(width: Screen.maxWidth, height: Screen.maxHeight*CGFloat(viewmodel.videoplayer.count))
        
        view.addSubview(childView.view)
        view.showsVerticalScrollIndicator=false
        view.showsHorizontalScrollIndicator=false
        view.contentInsetAdjustmentBehavior = .never
        view.isPagingEnabled=true
        view.delegate=context.coordinator
        return view
        
    }

在此處輸入圖像描述

在您的 makeUIView function 中試試這個:

childView.navigationController?.setNavigationBarHidden(true, animated: false)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM