A scroll view (UIScrollView) is a view whose content is larger than its bounds. To reveal a desired area, the user can scroll the content by dragging, or you can reposition the content in code.
A scroll view isn’t magic; it takes advantage of ordinary UIView features (Chapter 1). The content is simply the scroll view’s subviews. When the scroll view scrolls, what’s really changing is the scroll view’s own bounds origin; the subviews are positioned with respect to the bounds origin, so they move with it. The scroll view’s
clipsToBounds is usually
true, so any content positioned within the scroll view is visible and any content positioned outside it is not.
In addition, a scroll view brings to the table some nontrivial abilities:
As I’ve just said, a scroll view’s subviews, like those of any view, are positioned with respect to its bounds origin; to scroll is to change the bounds origin. The scroll view thus already knows how far it should be allowed to slide its subviews downward and rightward — the ...