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
}