开发者

SetFrame of the UIWebView

开发者 https://www.devze.com 2023-04-01 13:42 出处:网络
I\'m loading an HTML string into a UIWebView. When the UIWebView finishes loading, I resize its height like this:

I'm loading an HTML string into a UIWebView. When the UIWebView finishes loading, I resize its height like this:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    float newSize = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] floatValue];
    [self.webV开发者_Python百科iewContent setFrame:CGRectMake(self.webViewContent.bounds.origin.x,
         self.webViewContent.bounds.origin.y, 
         self.webViewContent.frame.size.width, 
         newSize)];

Everything works fine until a certain height. When the HTML string gets really long - 60 000px, for example - then I get a crash. Any ideas, how could I avoid the crash? I tried to find examples where a UIWebView is being tiled, but I couldn't find anything useful.


You're almost certainly running out of memory. I've determined through experimentation that UIWebView allocates memory based on the frame size. You can have a seemingly infinite contentSize and iOS will handle the memory for you as content scrolls in and out of the visible frame.

I had to give up on a design that tiled UIWebViews inside of a UIScrollView. BTW, this behavior changed somewhere around iOS 4.2. It used to be possible to tile UIWebViews with very large frame sizes and the memory was constrained by the frame size of the containing UIScrollView.

0

精彩评论

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

关注公众号