[英]Workaround for 'background-attachment: fixed' which is not working in iOS4
我正在努力获得具有固定背景图像的网页,因此当在UIWebView中滚动页面时图像不会移动。
我发现的是: background-attachment: fixed
在iOS4中不起作用(使用4.2.1)。 要仔细检查我在<head>
部分内准备了一个带有代码片段(下面)的页面,并且该页面在Mac上的Safari和Firefox下按预期工作,但在iPhone的Safari中没有这样做...
你有什么建议作为实现预期结果的解决方法? 我已经使我的UIWebView半透明并添加了UIImageView,因此我可以通过半透明页面看到“固定背景图像”。 不幸的是,当我滚动它的结束/开始边缘时,我可以看到UIWebView边框。
是否有任何正式的Apple资源/网页声明iOS4没有实现background-attachment: fixed
?
干杯!
PS上面提到的代码片段:
<style type="text/css">
body {
background: #ffffff url('image.jpg') fixed no-repeat;
background-attachment: fixed;
}
</style>
使用带有负z-index的背景div:
<head>
<style>
#background {
background: url("background.jpg") no-repeat;
position: fixed;
top: 0;
left: 0;
background-size: 320px 480px;
width: 320px;
height: 480px;
z-index: -1;
}
</style>
</head>
<body>
<div id="background"></div>
This body text appears over the fixed background and scrolls.
</body>
适用于iOS 5和iOS 6。
我不确定CSS发生了什么,并且没有机会自己查看,但我知道当我试图摆脱UIWebView的阴影时我使用了这段代码:
NSArray *sv = [NSArray arrayWithArray:[myWebView subviews]];
UIScrollView *webScroller = (UIScrollView *)[sv objectAtIndex:0];
NSArray *wsv = [NSArray arrayWithArray:[webScroller subviews]];
[[wsv objectAtIndex:6] setHidden:YES];
[[wsv objectAtIndex:7] setHidden:YES];
[[wsv objectAtIndex:8] setHidden:YES];
[[wsv objectAtIndex:9] setHidden:YES];
它摆脱了阴影。 我以为我得到了一个问题的答案但是当我找到它时, 这是唯一出现的问题。
它通过App Store检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.