Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView: what is the difference between contentOffset and bounds.origin?

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?

like image 613
verec Avatar asked Dec 24 '11 17:12

verec


People also ask

What is Contentoffset UIScrollView?

The point at which the origin of the content view is offset from the origin of the scroll view.

What is contentInset?

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.

What is a UIScrollView?

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.

What is Contentsize of scrollView?

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} .


1 Answers

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.

like image 111
jlehr Avatar answered Oct 29 '22 00:10

jlehr