iphone: View on top of UIWebView?

前端 未结 4 1249
-上瘾入骨i
-上瘾入骨i 2021-02-04 15:35

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,

4条回答
  •  天涯浪人
    2021-02-04 16:18

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

    And use the following code:

    Set a area for the address bar:

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

    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
    }
    

提交回复
热议问题