xcode UIWebView 和 CSS 固定位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14267527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIWebView and CSS fixed position
提问by tcd
I have a UIWebView
that uses a fixed position header.
我有一个UIWebView
使用固定位置的标题。
When the ViewController
that contains the UIWebView
is the initial view, there is no problem with the fixed position divs.
当ViewController
包含的UIWebView
是初始视图时,固定位置的div没有问题。
When I display that same ViewController
through a Modal segue, that's when the problem occurs.
当我ViewController
通过 Modal segue显示相同的内容时,这就是问题发生的时候。
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.
我第一次在页面上滚动时,div 会随着页面移动和滚动,但是一旦我第一次松开滚动,div 就会返回到它的固定位置,并且错误再也不会发生。
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
...
有任何想法吗?我已经看到iScroll
,它不像我想要的页面那样工作,而且我认为有一种更简单的方法,因为我只在UIWebView
...的初始加载时遇到问题。
回答by tcd
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%; }
.
我使用了一个 CSS 解决方法,将标题定位在左上角的绝对位置,并给主<div>
一个 an overflow-y: scroll;
,并保留body { height: 100%; }
.
This resulted in kind of a knock-off iScroll!
这导致了一种仿冒的 iScroll!
EDIT
编辑
Also, you can insert this:
此外,您可以插入:
-webkit-overflow-scrolling: touch;
-webkit-overflow-scrolling: touch;
Into the main <div>
css for a more native feel.
进入主<div>
css 以获得更原生的感觉。
回答by Axeva
Unfortunately. position: fixed
isn't reliable on iOS yet. This means you'll need to make compromises somewhere.
很遗憾。position: fixed
在 iOS 上还不可靠。这意味着您需要在某处做出妥协。
iScroll maywork, but it's a hack at best. Depending on the device it may not scroll fast enough to give that "fixed" look you want.
iScroll可能有用,但充其量只是一个黑客。根据设备的不同,它的滚动速度可能不够快,无法提供您想要的“固定”外观。
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.
一种。将您需要的任何固定到屏幕顶部的内容放在 ViewController 顶部的 UIView 中,并在其下方放置 UIWebView。
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.
C。不要使用故事板,从而消除 segue 的问题。
d. Redesign your HTML so the need for a fixed header is removed.
d. 重新设计您的 HTML,以便消除对固定标题的需求。
Tell us more about what's in this fixed header and maybe we can come up with other ideas.
告诉我们更多有关此固定标题中的内容的信息,也许我们可以提出其他想法。
回答by sqreept
position: fixed
doesn't yet work well on iOS.
position: fixed
在 iOS 上还不能很好地工作。
iScroll is a safer bet.
iScroll 是一个更安全的选择。