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.
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?
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):
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With