How to always makes a UIScrollView scrollable?
I have a
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?
- What to name images for iPhone 5 screen size?
- “Unknown class <MyClass> in Interface Builder file” error at runtime
- iOS Multi peer connectivity showing same device name twice
- Decode Base-64 encoded PNG in an NSString
- How can I connect iPhone and web service and get XML data?
- Force device rotation with +attemptRotationToDeviceOrientation failing
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):
- Cannot “save for Enterprise Deployment”, ios ipa
- Using the Swift if let with logical AND operator &&
- Xcode 8 UIButtons with constraints not showing up
- Swift: Terminating with uncaught exception of type NSException
- Xcode 5 – “iOS Simulator failed to install application” every time I switch simulators
- Easy way to see saved NSUserDefaults?
- Xcode: ld: library not found for -lAFNetworking
- Offline Map for Private Property with Navigation in iOS
- UITableView method cellForRowAtIndexPath not called
- Change UISegmentedControl selected index or value programmatically
- How to play a sound using Swift?
- ios class not found “Expected a type”
- Is it mandatory to call NSUserDefaults synchronize method?
- Is it possible to access the iPhone “Favorite” numbers?
- Change Text Color of Items in UIActionSheet – iOS 8