如何在iOS 5中爲UIWebView創建「拉動以刷新」?我找不到教程。如何使用Pull在WebView(iOS 5)中刷新?
我已經在Tab Bar應用程序中獲得WebView,並且想要使用「Pull to refresh」(刷新)來刷新WebView,就像Twitter一樣。
我在哪裏可以找到完整的教程?
謝謝
如何在iOS 5中爲UIWebView創建「拉動以刷新」?我找不到教程。如何使用Pull在WebView(iOS 5)中刷新?
我已經在Tab Bar應用程序中獲得WebView,並且想要使用「Pull to refresh」(刷新)來刷新WebView,就像Twitter一樣。
我在哪裏可以找到完整的教程?
謝謝
我不能提供一個教程,也許我會寫一個,但我認爲這是很簡單的, 我這樣做小幅修改SPPullView。在主要的UIViewController
Here you can grab the files (SPPullView.m and SPPullView.h).
相關的代碼是一樣的東西:
- (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];
}
您還可以添加一些邏輯或屬性,以防止用戶縮放,或暫時停用拉視圖,而縮放。
我寫了這個代碼,它工作正常。這可能會幫助你。
- (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];
}
'pull to refresh'對UIWebView來說真的沒有意義,因爲反彈向上滾動很常見,它會在一段時間後真的變得煩人。 – 2012-07-18 20:18:59
也許你可以嘗試搜索谷歌或SO:http://stackoverflow.com/questions/3223627/how-to-refresh-a-uiwebview-by-a-pull-down-and-release-gesture – 2012-07-18 20:19:44
@ RichardJ.RossIII它相當,看到我的評論... – 2012-07-18 20:23:03