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

verec picture verec · Dec 24, 2011 · Viewed 12.2k times · Source

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?

Answer

jlehr picture jlehr · Dec 25, 2011

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.