How to always makes a UIScrollView scrollable?

I have a UIScrollView. The scrollview.contentSize is set to the height of all subviews in the UIScrollView. When the height of the contentSize if greater than the height of the UIScrollView, it is perfectly scrolling when dragging the view. When the height of the contentSize is less than the height of the UIScrollView nothing is happening when I drag the view.

I think that is standard behavior, since there is really nothing to scroll. But I would like, that the UIScrollView is moving a bit anyway.

  • How to get iPhone SDK 2.2.1 for Xcode 3.2?
  • Swift: Errors when using different integer sizes
  • How to add UDID to the provisioning profile?
  • iOS8 Beta Ad-Hoc App Download (itms-services)
  • How can I add a link for a rate button with swift?
  • “Do Not Disturb” feature in iOS 6 How to implement?
  • A possible solution is to ensure, that the height of the contentSize is never less than the frame.height plus a small margin (i.e. 5px):

    CGSize scrollSize = self.frame.size;
    int defaultHeight = self.frame.size.height + 5;
    int contentHeight = self.webView.frame.origin.y + self.webView.frame.size.height;
    scrollSize.height = MAX(defaultHeight, contentHeight);
    [self.scrollView setContentSize:scrollSize];
    

    Is there a less hackish way to do this?

    Solutions Collect From Internet About “How to always makes a UIScrollView scrollable?”

    There are two properties on UIScrollView that sound like what you want:

    @property(nonatomic) BOOL alwaysBounceVertical; // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
    @property(nonatomic) BOOL alwaysBounceHorizontal; // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally
    

    Simply set one or both of them to YES and you will get the bounce effect.

    This can also be set in IB by checking the “Bounce Horizontally” and/or “Bounce Vertically” box(s):

    enter image description here