简体   繁体   中英

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.

How about setting

alwaysBounceVertical = YES

In Swift:

scrollView.alwaysBounceVertical = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM