Calling a method when UIWebView scrolls

后端 未结 4 657
天涯浪人
天涯浪人 2020-12-11 11:09

I have a UIWebView that contains a lot of text content. I need to be able to get the location of the UIWebView every time it moves. I am using this code to get the point:

相关标签:
4条回答
  • 2020-12-11 11:11

    I believe that if your header lists your VC as a UIScrollViewDelegate, you can use the -(void)scrollViewDidScroll:(UIScrollView *)scrollView method to find out when it scrolls.

    0 讨论(0)
  • 2020-12-11 11:13

    This is not correct. If you will use:

    @implementation UIWebView(CustomScroll)
    - (void) scrollViewDidScroll:(UIScrollView *)scrollView{
        [self.delegate scrollViewDidScroll: scrollView];
    }
    @end
    

    You will lose focus when try to enter data on page on iOS7 and more

    You need to implement custom class for UIWevView and overwrite scrollViewDidScroll:

    - (void) scrollViewDidScroll:(UIScrollView *)scrollView{
    [super scrollViewDidScroll:scrollView];
    [((id<UIScrollViewDelegate>)self.delegate) scrollViewDidScroll:scrollView];
    }
    
    0 讨论(0)
  • 2020-12-11 11:17

    if your requirement is to keep loading webview when user scrolls then you should paste your code into

    - (void)webViewDidStartLoad:(UIWebView *)webView
    
    0 讨论(0)
  • 2020-12-11 11:32

    You should extend UIWebView, like below

    @implementation UIWebView(CustomScroll)
    - (void) scrollViewDidScroll:(UIScrollView *)scrollView{
        [self.delegate scrollViewDidScroll: scrollView];
    }
    @end
    

    and implement scrollViewDidScroll on your controller like:

    - (void) scrollViewDidScroll:(UIScrollView *)scrollView{
        NSLog("webview scrolled");
    }
    

    and don't forget to set your controller to the delegate property of UIWebView.

    0 讨论(0)
提交回复
热议问题