0

如何在 iOS 5 中为 UIWebView 制作“拉动刷新”?我找不到教程。

我在标签栏应用程序中有一个 WebView,我想用 Twitter 之类的“拉动刷新”来刷新 WebView。

我在哪里可以找到完整的教程?

谢谢

4

3 回答 3

0

我无法提供教程,也许我会写一个,但我认为它很简单,我做了这个稍微修改了 SPPullView。

在这里您可以获取文件(SPPullView.m 和 SPPullView.h)。

主 UIViewController 中的相关代码类似于:

- (void)viewDidLoad
{   
    [super viewDidLoad];
    self.pullView = [[SPPullView alloc] initWithScrollView:self.webView.scrollView];
    [self.pullView setDelegate:self];
    [self.webView.scrollView addSubview:self.pullView];    
    [self.webView.scrollView setDelegate:self];
    for (UIView *subview in [self.webView.scrollView subviews] ) {
       subview.userInteractionEnabled = NO; // used to disable copy/paste, etc inside the webview
    }
    //[self doYourStuff];
}

//Called when the user pulls to refresh (this is when you should update your data)
- (void) pullViewShouldRefresh: (SPPullView *) view {
    [self updateYourStuff];
}

您还可以添加一些逻辑或属性来防止用户缩放,或者在缩放时暂时停用拉取视图。

于 2012-09-11T09:10:36.873 回答
0

这很好用:http: //blog.gomiso.com/2012/03/22/yet-another-pull-to-refresh-library/

于 2012-09-26T09:21:31.817 回答
0

我写了这段代码,它工作正常。这可能会对您有所帮助。

- (void)viewDidLoad
{
   [super viewDidLoad];

   NSString *fullURL = URL you want to hit;
   NSURL *url = [NSURL URLWithString:fullURL];
   NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
   webView.delegate = (id)self;
   [webView loadRequest:requestObject];

   UIRefreshControl *refreshControlOnPull = [[UIRefreshControl alloc] init];
   [refreshControlOnPull addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
   [webView.scrollView refreshControlOnPull]; //<- this is point to use. Add "scrollView" property.
}

-(void)handleRefresh:(UIRefreshControl *)refresh {
   // Reload my data
   NSString *fullURL = The Url you want to hit;
   NSURL *url = [NSURL URLWithString:fullURL];
   NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
   [webView loadRequest:requestObject];
   [refresh endRefreshing];
}
于 2016-10-31T10:58:57.757 回答