I have implemented an UIScrollView delegate as:
- (void) scrollViewDidScroll: (UIScrollView *) scrollView {
CGRect bounds = scrollView.bounds ;
CGPoint scrollLoc = scrollView.contentOffset ;
NSLog(@"bounds: %@ offset:%@"
, NSStringFromCGRect(bounds)
, NSStringFromCGPoint(scrollLoc)) ;
}
And whatever I do, scrolling or rotating the device, it seems that contentOffset
and bounds.origin
are always the same.
Why do we need a contentOffset if that is the same as the bounds origin, or what is the case when both are actually different?
The point at which the origin of the content view is offset from the origin of the scroll view.
The contentInset is how much the content is visually inset inside the scroll view. It is the custom distance that the content view is inset from the safe area or scroll view edges. contentInset allows you to specify margins or padding around the content in the scrollview.
UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView . A scroll view is a view with an origin that's adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the app's main window.
The content size of a scroll view doesn't change anything about the bounds of a scroll view and therefore does not impact how a scroll view composites its subviews. Instead, the content size defines the scrollable area. By default, a scroll view's content size is a big, fat {w:0, h:0} .
According to the docs:
The contentOffset property is always the current location of the top-left corner of the scroll bounds, whether scrolling is in progress or not.
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