UIWebView rotation and memory problem

Posted by Fer on Stack Overflow See other posts from Stack Overflow or by Fer
Published on 2010-06-02T06:48:34Z Indexed on 2010/06/02 6:53 UTC
Read the original article Hit count: 697

Filed under:
|
|
|

Hi. I have an UIWebView that loads a embedded XHTML like this:

body = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; body.scalesPageToFit = YES; body.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; body.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

[self.view addSubview:body]; [body loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"article16" ofType:@"xhtml"]isDirectory:NO]]];

This XHTML have a lot of images, and when I rotate the device I got some memory warnings, and sometimes the app crashes. If I remove the autoresizing mask, specifically the UIViewAutoresizingFlexibleWidth (I have tryed with only UIViewAutoresizingFlexibleLeftMargin and UIViewAutoresizingFlexibleRightMargin with no problems), the memory warning stops, and the app does not crash anymore.

If I remove all autoresizing mask, and set the new webView frame in didRotate or willRotate, I got the same warnings as using the UIViewAutoresizingFlexibleWidth.

There's a app, called Atomic Web that could open the same XHTML and rotate with no memory warnings, and safari can open it as well, but if I create a project with only that UIWebView, the app sometimes crashes.

Someone knows what this may be? Can I set the webview frame in other way? Why can't I use the autoresizing mask?

Thanks for your attention.

© Stack Overflow or respective owner

Related posts about memory

Related posts about ipad