views:

117

answers:

1

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 shows 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.

A: 

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];

Luke Mcneice