简体   繁体   中英

Too many images causes UIWebView to flash white when loading web page

We're building an iPhone app by basically wrapping a web site inside a UIWebView. We're not using PhoneGap, just a UIWebView to load a mobile app built with jQuery and jQuery Mobile.

If we show more than two images at once, the web page flashes white for a second. If we limit the number of loaded images to two, there is no flash, and the page loads normally.

Does UIWebView have trouble rendering more than X MB in images?

Any clues why?

Probably easier to apply this in the css sheet so it affects all your divs and images. I found it worked wonders for me when I ran into the off-screen rendering issue

 div, img {
    -webkit-transform:translateZ(0);    
 }

Edit:

For the images, change "src" to "data-src" and then add this script to your footer, assuming you are running jquery:

$(document).ready(function() {
    $('img').each(function(){
        var $imgSrc = $(this).attr("data-src");
        $(this).attr("src", $imgSrc);
    });
});

This will make it so the images load once the raw body code has loaded, which will take less than a second, and should hopefully prevent the white flash problem.

No clue why this worked, but capping the page height at 460px (iPhone app) eliminated the flash. Maybe some conflict with JQM and setting of the height?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM