UIWebView and CSS fixed position

眉间皱痕 提交于 2019-12-23 03:09:11

问题


I have a UIWebView that uses a fixed position header.

When the ViewController that contains the UIWebView is the initial view, there is no problem with the fixed position divs.

When I display that same ViewController through a Modal segue, that's when the problem occurs.

The first time I scroll on the page, the divs move and scroll with the page, but once I let go of scrolling for the first time, the div returns to its fixed position and the error never happens again.

Any ideas? I've seen iScroll, it doesn't quite work like I want the page too, and I think there's an easier way, since I only get the problem on the initial load of the UIWebView...


回答1:


I used a CSS workaround, positioning the header as absolute in the top left corner, and giving the main <div> an overflow-y: scroll;, and keeping the body { height: 100%; }.

This resulted in kind of a knock-off iScroll!

EDIT

Also, you can insert this:

-webkit-overflow-scrolling: touch;

Into the main <div> css for a more native feel.




回答2:


Unfortunately. position: fixed isn't reliable on iOS yet. This means you'll need to make compromises somewhere.

iScroll may work, but it's a hack at best. Depending on the device it may not scroll fast enough to give that "fixed" look you want.

You haven't given us much detail about what is in this header, but here are a few other possibilities:

a. Place anything you need fixed to the top of the screen in a UIView at the top of your ViewController, with the UIWebView below it.

b. Change your storyboard flow to eliminate the need for a modal segue.

c. Don't use storyboards, thus eliminating the problem with the segue.

d. Redesign your HTML so the need for a fixed header is removed.

Tell us more about what's in this fixed header and maybe we can come up with other ideas.




回答3:


position: fixed doesn't yet work well on iOS.

iScroll is a safer bet.



来源:https://stackoverflow.com/questions/14267527/uiwebview-and-css-fixed-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!