Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView doesn't bounce

I have a UIScrollView contained within a custom UIView with a content size larger than the ScrollView's frame.

I am able to drag scroll as I expect, but the thing doesn't give me the rubber banding effect that you get with the UITableView or UIWebView. It just stops when you get to one of the extremes.

I have set bounce = YES, is there something else I'm supposed to do?

I read the docs, and they say I have to implement the delegate. I did that.

They also say I should change the zoom levels, but I don't want the user to actually be able to zoom so I haven't set these.

like image 434
Frank Krueger Avatar asked Apr 16 '10 14:04

Frank Krueger


People also ask

What is bounce on scroll Swift?

Bouncing visually indicates that scrolling has reached an edge of the content. If the value is false , scrolling stops immediately at the content boundary without bouncing. The default value is true .

What is scroll view in Swift?

The scroll view displays its content within the scrollable content region. As the user performs platform-appropriate scroll gestures, the scroll view adjusts what portion of the underlying content is visible. ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality.


3 Answers

For anyone that finds this thread later, if you are subclassing UIView and re-setting the UIScrollView's frame on every layoutSubviews, that is the problem - it cancels the bounce:

http://openradar.appspot.com/8045239

You should do something similar to this:

- (void)layoutSubviews;
{
    [super layoutSubviews];

    CGRect frame = [self calculateScrollViewFrame];
    if (!CGRectEqualToRect(frame, self.scrollView.frame)) 
        self.scrollView.frame = frame;
}
like image 188
leolobato Avatar answered Nov 16 '22 00:11

leolobato


I had the same problem, on a UIScrollView that wasn't all filled up (but I still wanted it to bounce). Just setted:

scroll.alwaysBounceVertical/Horizontal = YES;

And it worked as expected

like image 40
tinsukE Avatar answered Nov 16 '22 00:11

tinsukE


It turns out that keeping the UIScrollView within my custom UIView was causing the trouble.

Once I switched my custom UIView to instead inherit from UIScrollView, then the bouncing started working.

like image 43
Frank Krueger Avatar answered Nov 16 '22 01:11

Frank Krueger