我正在开发一个显示嵌入在WebView中的PDF的应用程序,这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *urlremoto = [NSURL URLWithString:@"https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/TransitionGuide.pdf"];
request = [NSURLRequest requestWithURL:urlremoto];
[self.webView loadRequest:request];
[self.webView setScalesPageToFit:YES];
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
[self.activityIndicator startAnimating];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
//TODO: describir el error
[self.activityIndicator stopAnimating];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
[self.activityIndicator stopAnimating];
}
Run Code Online (Sandbox Code Playgroud)
现在,我想触摸一个按钮,然后将加载的PDF更改为特定页面,我正在寻找实现这一目标的方法,但是仍然无法正常工作
预先感谢您的支持
目前我认为你可以使用两种方法:
使用scrollView在PDF中“导航”:
[[webView scrollView] setContentOffset:CGPointMake(0,y) 动画:YES];
// 例如,跳转到页面高度为 1000 px 的 PDF 文档中的第 5 页:
int selectedPag = 5; // i.e. Go to page 5
float pageHeight = 1000.0; // i.e. Height of PDF page = 1000 px;
float y = pageHeight * selectedPag;
[[webView scrollView] setContentOffset:CGPointMake(0,y) animated:YES];
Run Code Online (Sandbox Code Playgroud)拆分 PDF 单个页面。