Fixed header disappear when scrolling down in webview in iOS 11

21,662

Solution 1

I'm just writing some code, try with one by one

From Apple official note:

Important:

Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app. Do not use UIWebView or WebView.

So you should try once with WKWebView.

Solution 2

position: fixed has always been a problem with iOS. It seems that in every version of iOS the problem persists. Now, I couldn't find anything regarding the change of behaviour of your application from iOS 10 to 11, you could consider reporting this as a bug; on the other hand having seen the multitudes of people who encountered this problem and the fact that affects more or less all the recents versions of iOS I would suggest not to use position: fixed.

The most common workaround is transform: translateZ(0), this not only works on iOS and prevent any possible flickering, it also forces the browser to use hardware acceleration to access the GPU to make pixels fly. It should work also without the prefix -webkit- from iOS 9.

Solution 3

I had this very similar issue with a Cordova project built for iOS, which uses a webview. Cordova uses the UIWebView by default as its webview engine and I tried all the possible fixes mentioned in this thread and many others. Finally our only solution was to change the webview engine from UIWebView to WKWebView (https://developer.apple.com/documentation/webkit/wkwebview). With Cordova, introducing the WKWebView is pretty straightforward with a plugin https://github.com/apache/cordova-plugin-wkwebview-engine

After introducing WKWebView and dealing with some of the issues it causes we are no longer experiencing the flickering or disappearing fixed positioned elements while scrolling in iOS 11.

Solution 4

We had the similar issue and it got fixed with below 2 plugins

https://github.com/apache/cordova-plugin-wkwebview-engine https://github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix

First plugin will change default WebView to WKWebView and second plugin provide fix for CORS issue that we see for using WKWebView.

Solution 5

The trick is to force GPU acceleration. Do this by adding translate3d to the #header element.

transform: translate3d(0,0,0);

If elements nested inside the #header element continue to disappear add translate3d to them as well.

Share:
21,662
Bergerova
Author by

Bergerova

Updated on June 14, 2020

Comments

  • Bergerova
    Bergerova about 4 years

    I have a native iOS app with a webview to display web content. I have a fixed header in my app with the following properties:

    #header {
        height: 60px;
        background-color: @mainColor;
        color: #ffffff;
        padding: 10px;
        text-align: center;
        position: fixed;
        width: 100%;
        z-index: 1;
    }
    

    Before I upgraded to iOS 11 everything worked fine. Now when I scroll down/up the header disappears during the scroll, and when the scroll is done, the header appears again.

    This can also be reproduced in Xcode 8.

  • Bergerova
    Bergerova over 6 years
    I have tried using transform: translateZ(0), but it doesn't fix the problem
  • Bergerova
    Bergerova over 6 years
    I have tried using transform: translate3d(0,0,0), but it doesn't fix the problem
  • Dedering
    Dedering over 6 years
    What happens if you apply translate3d(0,0,0) to #header * { and target the nested elements as well?
  • David Schumann
    David Schumann over 6 years
    Doesn't fix this problem for me either
  • David Schumann
    David Schumann over 6 years
    This fixed it for me too. But it breaks other stuff, like downloading and accesssing files. How is this not a bigger issue? Cordova pracitcally being unusable for the newes iOS release?
  • Akash Pal
    Akash Pal over 6 years
    It didnt work for me, somehow my angular didnt load, just have a blank screen.
  • Huw Davies
    Huw Davies over 6 years
    not working for my case either :( and this element is position: relative;
  • Paolo Forgia
    Paolo Forgia over 6 years
    Apparently this solution worked until iOS 11, when I'll found a solution I'll update this answer. Thank you for the feedback
  • Huw Davies
    Huw Davies over 6 years
    @PaoloForgia you're quite right, it's now an issue in iOS11 and I think it'll cause quite a lot of people problems!
  • Bergerova
    Bergerova over 6 years
    Hi, thank for your answer. I already tried this solution, but as you said, it cannot be a valid solution in production. The scrolling becomes very slow...
  • Oook
    Oook over 6 years
    Yeah... I wish I had something better to report. This issue is making me nuts. It doesn't help that I'm fairly new to this sort of thing. I'll keep working on it and watching this space. Somebody has to come up with a solution sooner or later.
  • abarax
    abarax over 6 years
    This answer is actually working for me. I'm not sure if it's appropriate to reward the bounty for it though, as it does not solve the problem with the standard UIWebView. However if we hit the deadline this might be the one that gets it.
  • Penar
    Penar over 6 years
    This worked great for a fixed-positioned element that doesn't show up on first load in a WKWebview (but does display after scrolling). Thanks!
  • Igor Trindade
    Igor Trindade over 6 years
    That's worked perfect for me! Actually event improved the usability of my app with this wkwebview engine... Thanks a lot!!!
  • Akash Pal
    Akash Pal over 6 years
    This worked perfectly. Still have to test the app fully with WKWebView. Important: Important Note: Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app. Do not use UIWebView or WebView.
  • Claes Gustavsson
    Claes Gustavsson about 6 years
    Dilip, Im using phonegap build and the engine plugin is on npm so it installs. But how do I install the wkwebviewxhrfix? Do I include the folder src/ios to my project? Thanks.
  • Dilip
    Dilip about 6 years
    @ClaesGustavsson - Try with "phonegap plugin add github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix". If that does not help, you can probably download the whole repo from github on your project folder and then install the same from there.
  • Claytronicon
    Claytronicon about 6 years
    I had this same issue, and position:sticky did the same thing. Changing to WKWebView fixed it
  • Claes Gustavsson
    Claes Gustavsson about 6 years
    Thanks Dilip. With the github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix can I load file from my server with that or just local files in the phone?
  • Dilip
    Dilip about 6 years
    You should be able to install from the server. "phonegap plugin add github.com/TheMattRay/cordova-plugin-wkwebviewxhrfix" not working ?
  • sdym
    sdym over 2 years
    Now I have a display issue on iOS 14 & iOS 15, this acceleration method is not working. The fixed header would have a 1-pixel gap above occationally when I do scrolling.