iphone: View on top of UIWebView?

前端 未结 4 1242
-上瘾入骨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:03

    There is a way, but I am not sure if it is a bit too hacky. First search for the scrollview within the webview, then alter the contentInset and finally add the searchbar(for example) to the scrollview. The following code is just an example, I did not set any frames correctly and 40 is just a made up height for the searchbar. I am not sure if this will work in every iOS Version.

    UIWebView * myWebView = [[UIWebView alloc] init]
    UISearchBar * mySearchBar = [[UISearchBar alloc] init];
    for (NSObject * aSubView in [myWebView subviews]) {
       if ([aSubView isKindOfClass:[UIScrollView class]]) {
          UIScrollView * theScrollView = (UIScrollView *)aSubView;
          theScrollView.contentInset = UIEdgeInsetsMake(40, 0, 0, 0);
          [theScrollView addSubview:mySearchBar];
       }
    }
    

提交回复
热议问题