博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
在xib文件中拖入UIWebView。
使用代码为UIWebView的滚动控件增加搜索栏:
UISearchBar* searchBar=[[[UISearchBar alloc]initWithFrame:CGRectMake(0, -44, 320, 44)]autorelease];
    [self.browser.scrollView addSubview:searchBar];
    self.topBar=searchBar;
 [[self.browser scrollView] setContentInset:UIEdgeInsetsMake(44, 0, 0, 0)];
    self.browser.scrollView.scrollIndicatorInsets=UIEdgeInsetsMake(44, 0, 0, 0);
    [self.browser.scrollView setContentOffset:CGPointMake(0, -44)];//webview加载后会默认给滚动条设置滚动位置为0,0。
    self.browser.scrollView.delegate=self;//给滚动条加代理来调整滚动条指示控件的位置
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    float y=scrollView.contentOffset.y;
    if (y>0) {//topbar不可见
         scrollView.scrollIndicatorInsets=UIEdgeInsetsMake(0, 0, 0, 0);
    }else{//topbar可见
        scrollView.scrollIndicatorInsets=UIEdgeInsetsMake(-y, 0, 0, 0);
    }
}
//删除UIWebView的阴影效果
 UIView* lastView = [[[[self.browser subviews] objectAtIndex:0] subviews] lastObject];
    for(UIView *wview in [[[self.browser subviews] objectAtIndex:0] subviews]) { 
        if([wview isKindOfClass:[UIImageView class]]) { 
            if (wview!=lastView) {//this is scroll indicator
                 wview.hidden = YES; 
            }
        }
    } 

转http://qiufangzhou.blog.163.com/blog/static/506421802012347019554/ 

 

UIWebView的Scroll事件的监测

http://three20.pypt.lt/uiwebview-tap-scroll-detection 

 

 

posted on 2012-04-28 17:53  Likwo  阅读(1066)  评论(0编辑  收藏  举报