将标题视图添加到类似于Safari和文章的UIWebView [英] Adding a header view to a UIWebView similar to Safari and Articles
问题描述
我想将标题视图添加到 UIWebView
,类似于MobileSafari中的地址/搜索栏和Sophia Teutschler的优秀Articles.app。更准确地说,我想在UIWebView上创建一个拉动修复方向视图,就像在文章中一样。文章确实使用UIWebView,所以它似乎是可能的。有没有办法实现这一点,而无需将 UIWebView
嵌入 UIScrollView
并不断更新其大小,如这篇文章中所述?显然,我确实需要滚动事件让拉动修复方向相应地表现出来。
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子视图]
- 寻找最大的,它应该包含浏览器(其他的是阴影和线条)
-
更改它的origin.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];
}
这篇关于将标题视图添加到类似于Safari和文章的UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!