Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

iphone - Adding a header view to a UIWebView similar to Safari and Articles

I'd like to add a header view to an UIWebView similar to the address/search bar in MobileSafari and the excellent Articles.app by Sophia Teutschler. More precisely, I'd like to create a "pull to fix orientation" view above a UIWebView, just like in Articles. Articles does use a UIWebView, so it seems to be possible. Is there a way to accomplish this without having to embed the UIWebView into a UIScrollView and updating its size all the time, as described in this article? Apparently, I do need the scrolling events to have the "pull to fix orientation" behave accordingly.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

After several attemps, I've decided to go with this solution:

Basically I've just added my header UIView as a webview.scrollview subview.

To avoid having the header overlap the browser view:

  • cycle through all [webview.scrollView subviews]
  • look for the biggest, wich should contains the browser (the others are for shadows and lines)
  • change its origin.y

    here's the code:

    CGRect browserCanvas = web.bounds;
    for(int i=0; i< [[web.scrollView subviews] count]; i++)
    {
      UIView* subview = [[web.scrollView subviews] objectAtIndex:i];
      CGRect f = subview.frame;
      NSLog(@"sub %d -> x:%.0f, y:%.0f, w:%.0f, h:%.0f", i, f.origin.x, f.origin.y, f.size.width, f.size.height);
    
      if(f.origin.x == browserCanvas.origin.x && 
         f.origin.y == browserCanvas.origin.y && 
         f.size.width == browserCanvas.size.width && 
         f.size.height == browserCanvas.size.height)
         {
             f.origin.y = header.frame.size.height;
             subview.frame = f;
         }
    }
    
    if(![header superview])
    {
      [web.scrollView addSubview:header];
      [web.scrollView bringSubviewToFront:header];
    }
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...