Billy
Billy

Reputation: 185

How to enable elasticity in WebView?

When developing OS X apps in Cocoa, WebView does not have over-scroll elasticity (i.e., the bouncy scrolling that Safari has on OS X). How do you enable it?

Upvotes: 3

Views: 537

Answers (1)

Billy
Billy

Reputation: 185

After much putzing, I figured out the answer. The key is to get a handle of the scroll view that WebView creates (but does not publicly expose). Here is how to do it:

- (void)awakeFromNib
{
    [self setMainFrameURL:@"http://www.stackoverflow.com"];
    NSScrollView * scrollView = (NSScrollView *)([[[self mainFrame] frameView] subviews][0]);
    [scrollView setHorizontalScrollElasticity:NSScrollElasticityAutomatic];
    [scrollView setVerticalScrollElasticity:NSScrollElasticityAutomatic];
}

Note that this needs to be done whenever the frame's URL is set.

Upvotes: 3

Related Questions