rnystrom
rnystrom

Reputation: 1916

Frame of UIWebView inside UIScrollView does not stretch size to fit all of contents

In a small app that is loading web content from a blog, the UIWebView (which is inside a UIScrollView to be scrollable) will not scroll all of the content into view if it is longer than the actual UIScrollView's frame. Here is an image of the problem:

https://i.sstatic.net/k3Hkl.png

The code that loads the UIScrollView and the UIWebView (this is part of a UIViewController)

- (id)initWithHTML:(NSString*)html
{
    self = [super init];
    if (self) {
        CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
        UIScrollView* v = [[UIScrollView alloc] initWithFrame:appFrame];
        self.view = v;

        UIWebView* webView = [[UIWebView alloc] initWithFrame:v.frame];
        webView.userInteractionEnabled = NO;
        webView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:webView];

        [webView loadHTMLString:html baseURL:nil];
        CGSize sz = v.bounds.size;
        sz.height = webView.bounds.size.height + 20;
        v.contentSize = sz;        

        [v release];
        [webView release];
    }
    return self;
}

Upvotes: 1

Views: 1166

Answers (1)

ms83
ms83

Reputation: 1814

From Apple's documentation:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

It could be that when you are scrolling the events are getting mixed up. This could be the reason why its preventing you from scrolling the rest of the content into view.

Upvotes: 1

Related Questions