问题描述
我想向 uiwebview 添加一个标题视图,类似于 mobilesafari 中的地址/搜索栏和 sophia teutschler 的优秀 articles.app.更准确地说,我想在 uiwebview 上方创建一个拉动固定方向"视图,就像在文章中一样.文章确实使用了 uiwebview,所以这似乎是可能的.如 这篇文章?显然,我确实需要滚动事件以使拉动以固定方向"行为相应.
i'd like to add a header view to an uiwebview similar to the address/search bar in mobilesafari and the excellent articles.app by sophia teutschler. more precisely, i'd like to create a "pull to fix orientation" view above a uiwebview, just like in articles. articles does use a uiwebview, so it seems to be possible. is there a way to accomplish this without having to embed the uiwebview into a uiscrollview and updating its size all the time, as described in this article? apparently, i do need the scrolling events to have the "pull to fix orientation" behave accordingly.
推荐答案
经过几次尝试,我决定采用这个尊龙凯时的解决方案:
after several attemps, i've decided to go with this solution:
基本上我刚刚将我的标题 uiview 添加为 webview.scrollview 子视图.
basically i've just added my header uiview as a webview.scrollview subview.
为避免标题与浏览器视图重叠:
to avoid having the header overlap the browser view:
- 循环浏览所有 [webview.scrollview 子视图]
- 寻找最大的,应该包含浏览器(其他用于阴影和线条)
改变它的起源.y
- cycle through all [webview.scrollview subviews]
- look for the biggest, wich should contains the browser (the others are for shadows and lines)
change its origin.y
代码如下:
cgrect browsercanvas = web.bounds;
for(int i=0; i< [[web.scrollview subviews] count]; i )
{
uiview* subview = [[web.scrollview subviews] objectatindex:i];
cgrect f = subview.frame;
nslog(@"sub %d -> x:%.0f, y:%.0f, w:%.0f, h:%.0f", i, f.origin.x, f.origin.y, f.size.width, f.size.height);
if(f.origin.x == browsercanvas.origin.x &&
f.origin.y == browsercanvas.origin.y &&
f.size.width == browsercanvas.size.width &&
f.size.height == browsercanvas.size.height)
{
f.origin.y = header.frame.size.height;
subview.frame = f;
}
}
if(![header superview])
{
[web.scrollview addsubview:header];
[web.scrollview bringsubviewtofront:header];
}
菊花残满腚伤-一枪热流穿断肠