How to refresh a UIWebView by a “pull down and release” gesture?

给你一囗甜甜゛ 提交于 2019-12-18 10:56:41

问题


I know that this is possible in the Tweetie for iPhone or the xkcd iPhone app, but they are using a table. Any idea if this can be done for a simple UIWebView as well? I'm aware of the Javascript suggestions in this SO question, but what about making that natively?


回答1:


FYI, iOS 5 has officially introduced the property scrollView in UIWebView. I tested it. It worked perfectly with EGO's pull and refresh code. So the problem is no longer a problem for any iOS 5 devices.

For downward compatibility, you still need @CedricSoubrie's code though.




回答2:


To retrieve scroll events on UIWebView I personnaly use this code to get the scrollview that is inside the UIWebView :

- (void) addScrollViewListener
{
    UIScrollView* currentScrollView;
    for (UIView* subView in self.myWebView.subviews) {
         if ([subView isKindOfClass:[UIScrollView class]]) {
            currentScrollView = (UIScrollView*)subView;
            currentScrollView.delegate = self;
        }
    }
}

It's working. You can also use it to call [(UIScrollView*)subView setContentOffset:offSet animated:YES]; The only problem may be not to pass Apple code checking. I don't know yet since I'm still in coding phase.

Anyone tried that yet ?




回答3:


To tell the truth, UIWebVIew class has an undocumented getter method called _scrollView; So the code goes:

scrollView = [webView _scrollView];




回答4:


To get a reference for the UIScrollView in UIWebView, simply search it by iterating trough subviews.

for(id eachSubview in [webView subviews]){
        if ([eachSubview isKindOfClass:[UIScrollView class]]){
            scrollView = eachSubview;
            break;
        }
}

After that you can easily wire up things to your EGORefreshTableHeaderView interface with the UIWebView and the UIScrollView delegate callbacks.



来源:https://stackoverflow.com/questions/3223627/how-to-refresh-a-uiwebview-by-a-pull-down-and-release-gesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!