My ViewController WITH Large Navigation Bar Scrollers up automatically After loading WKWebView

Viewed 434

In my app, I am loading about the page in a view controller with a WebKit WebView, and Viewcontroller has a Large Navigation Controller. At time of view DidLoad Large navigation bar is shown fine.

At this point when I start loading my WebView with a local HTML file. After loading this WebView, without any user interaction, ViewController automatically scrolls up such that navigation bar shrink to actual small-sized form. enter image description here

5 Answers

Yes this is the default behaviour of navigation bar if you want to set large navigation bar all the time then you have to go with custom navigation bar. Create your own Navigation bar. Thanks

What will help you is the use of viewLayoutMarginsDidChange() .Using this you can check in everyview if the view size has changed and if so you can set your original navigation title size here , So instead of what i have added , parse your Navigation bar frame values below.

     var didChange = false
    override func viewLayoutMarginsDidChange() {
    if didChange {
        print("Height : - \ 
  (self.navigationController?.navigationBar.frame.size.height)")
    // set NavigationBar Height here    
       self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: 
   UIScreen.main.bounds.width, height: 96.0)
        didChange.toggle() 
        }
     }

Try getting the scroll events of wkWebView.srollView in scrollViewDidScroll , see if something make it scroll.

Or , disable WKWebView.scrollView.scrollEnabled when loading the WebView and enable it back when load completes

Change the contentInsetAdjustmentBehavior property of the ScrollView of WebView to .never in your viewDidLoad method.

webView.scrollView.contentInsetAdjustmentBehavior = .never

You can try :

webView.scrollView.contentInsetAdjustmentBehaviour = .never
Related