将标题视图添加到类似于 Safari 和文章的 UIWebView

Adding a header view to a UIWebView similar to Safari and Articles(将标题视图添加到类似于 Safari 和文章的 UIWebView)
本文介绍了将标题视图添加到类似于 Safari 和文章的 UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想向 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];
}

这篇关于将标题视图添加到类似于 Safari 和文章的 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滚动)
How can i add a activity indicator below the UITableView?(如何在 UITableView 下方添加活动指示器?)
NSURLRequest won#39;t fire while UIScrollView is scrolling(NSURLRequest 在 UIScrollView 滚动时不会触发)