我正在尝试下载一个pdf,在下载时我想显示其预览或显示pdf的某些部分,下载到webview
你可以这样做,
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)]; //whatever size you want
NSURL *targetURL = [NSURL URLWithString:@"your url for pdf here"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
[self.view addSubview:webView];
你可以试试GCD
当你下载pdf时,你可以在webview中显示预览。它可以同时下载和显示预览。
对于这个GCD是一个很好的使用。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// Do the back ground process
......Downloading the coding of pdf here
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI here
.....Do the webview coding
});
});
全球队列异步任务将在这里执行。它不会等待。异步函数不会阻止当前正在执行的线程继续执行下一个函数。
主要队列我们必须总是在主线程上访问uikit类。
Ray wanderlich示例