Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 253
Billy Avatar asked Dec 01 '25 10:12

Billy


1 Answers

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.

like image 194
Billy Avatar answered Dec 05 '25 07:12

Billy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!