Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UIScrollView always scrollable

I'm trying to make a class (ScrollableView : UIScrollView) that can always scroll vertically, similar to a TableView. I've hardcoded a constant value to add to the content size so that it can always be scrollable. For some strange reason though, it won't work when the value is 1; it will only work if the value is 4 or more.

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.contentSize = CGSizeMake(frame.size.width, frame.size.height+1);
        self.scrollEnabled = YES;
    }
    return self;
}

Is there another way to do this? This doesn't seem to be the proper way.

like image 893
Justin Avatar asked Apr 06 '11 05:04

Justin


People also ask

How does UIScrollView work?

A floating-point value that determines the rate of deceleration after the user lifts their finger. We can assume that this rate indicates how much the scroll velocity will change after one millisecond (all UIScrollView values are expressed in milliseconds, unlike UIPanGestureRecognizer ).


1 Answers

How about setting

alwaysBounceVertical = YES

In Swift:

scrollView.alwaysBounceVertical = true
like image 119
Kris Van Bael Avatar answered Oct 22 '22 01:10

Kris Van Bael