Frank Krueger
Frank Krueger

Reputation: 71063

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.

Upvotes: 16

Views: 11189

Answers (3)

user477243
user477243

Reputation:

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

Upvotes: 30

leolobato
leolobato

Reputation: 2379

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;
}

Upvotes: 47

Frank Krueger
Frank Krueger

Reputation: 71063

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.

Upvotes: 3

Related Questions