Navigating a Pdf using UIWebview not working in IOS 5

血红的双手。 提交于 2019-12-20 07:14:58

问题


I have recently upgraded to Xcode 4 and I've found that an app which has worked perfectly well for over a year is now not working under Ios 5. The app navigates a Pdf in UIWebview and uses the following code to move to any page within the Pdf.

[self.pdfNavigateController.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"window.scrollTo(0, %d);", self.pdfNavigateController.scrollPosition]];

When I use any simulator from 4.2 down the code works perfectly but under the Ios 5 simulator the code wont work.

Looking through the forum there seems to be a number of issues where classes have changed. What has changed under Ios 5 and what can I do to rectify the problem?


回答1:


You can use UIWebView's Scrollview for navigation as Javascript is no more supported: Below is a my code worked fine for me.

    [aWebView.scrollView setContentOffset:CGPointMake(x, y)];

The contentOffset accepts a CGPoint as argument. Here x and y are integer values representing the scrollPosition. If you want to get current x and y co-ordinates for webView, below is the code which you can use:

NSInteger x = aWebview.scrollView.contentOffSet.x;
NSInteger y = aWebview.scrollView.contentOffset.y;

Note: ScrollView is introduced in IOS 5 and will not work on earlier IOS versions. Javascript function are available for earlier versions. So you can check for device version and implement code accordingly.



来源:https://stackoverflow.com/questions/8039367/navigating-a-pdf-using-uiwebview-not-working-in-ios-5

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