开发者

ipad orientation problem with webview

开发者 https://www.devze.com 2023-01-11 15:09 出处:网络
I\'m creating ipad application. It has just 2 views. One view has few buttons. On click of a button it will open another view. This view has a webview which sho开发者_开发技巧ws PDF file. I\'m using t

I'm creating ipad application. It has just 2 views. One view has few buttons. On click of a button it will open another view. This view has a webview which sho开发者_开发技巧ws PDF file. I'm using the following code to show the PDF

- (void)viewDidLoad {
[super viewDidLoad];
NSString* path = [[NSBundle mainBundle] pathForResource:@"mypdf" ofType:@"pdf"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];

}

Now the problem is that, when I change the orientation, whole view is rotating, but the pdf is being disturbed and not rendering properly. how can I avoid this?

As the PDF is having 250 pages, reloading the whole PDF on willRotateToInterfaceOrientation and didRotateFromInterfaceOrientation will delay the display.

How to avoid this situation.


There has to be a way a better to avoid/fix this, for now i just read the y scroll position with:

int scrollPosition = [[webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

Then reloaded the document in:

(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;

and then set the scroll position again with:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号