iphone:在UIWebView上查看? [英] iphone: View on top of UIWebView?

查看:85
本文介绍了iphone:在UIWebView上查看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个浏览器应用程序,我在UIWebView上有一个地址栏。在MobileSafari上,如果向下滚动,地址栏将开始移动到屏幕顶部,UIWebView不会滚动。只有当地址栏完全消失时,它才会开始滚动。我想在我的应用程序中也有这个效果。

I'm working on a browser app, and I have an address bar on top the UIWebView. On MobileSafari if you scroll down, the address bar starts to move to the top, out of the screen, and the UIWebView doesn't scroll. Only when the address bar disappears completely, it starts to scroll. I would like to have this effect in my app as well.

实现这个的最佳方法是什么?

What's the best way to implement this?

谢谢

推荐答案

实现这一目标的唯一方法是iOS 5.
在iOS 5中,UIWebView有一个UIScrollView子视图。

The only way to implement this requires iOS 5. In iOS 5, UIWebView has an UIScrollView subview.

并使用以下代码:

设置地址栏的区域:

[[myWebView scrollView] setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];

使用scrollview委托移动地址栏:

Move the address bar using the scrollview delegate:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

        if(scrollView.contentOffset.y>=-64&&scrollView.contentOffset.y<30)
        {
            topBar.frame=CGRectMake(0,-44-scrollView.contentOffset.y, 320, 44);

        }
        else if(scrollView.contentOffset.y<-64)
            topBar.frame=CGRectMake(0,20, 320, 44);//Lock the position
}

这篇关于iphone:在UIWebView上查看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆