iPhone - Make a UIWebView subview scrolling to top

2019-04-14 17:03发布

I have a mainView that contains :

  • a paginated scrollView,
  • a page Control
  • a close button

and each page of the scrollView contains a subview that contains a webView.

The user can go left to right from pages to pages, and scroll up and down each webView.

But... how can I make the currently displayed webView scroll to top when the user touches the status bar ?

EDIT : for iOS4 of course.

2条回答
Bombasti
2楼-- · 2019-04-14 17:24
  1. If you are building your application against iOS 5 base SDK, you can use now public property "scrollView" in UIWebView, using that you can scroll to whatever offset you desire to.

  2. If you are building for SDK < 5.0, it can be done in another way using HTML features. You can use Anchor tag somewhere at the top in your HTML code, at the very beginning just after tag begins, include this anchor:

    < A NAME="top_of_page">

Now when user taps on the the status bar, make this action trigger:

<A HREF="#top_of_page">

Somehow, not pretty sure how though!

Perhaps by using:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script

???

查看更多
时光不老,我们不散
3楼-- · 2019-04-14 17:34
[yourPaginatedScrollView setScrollsToTop:NO];
[(UIScrollView *)[yourWebView.subviews objectAtIndex:0] setScrollsToTop:YES];

The first line is important too else two scrollviews will be assigned => iOS can't really choose, so it'll decide no scrollview scrolls to top when you touch the status bar.

查看更多
登录 后发表回答