Skip to Content
Programming iOS 10
book

Programming iOS 10

by Matt Neuburg
November 2016
Beginner to intermediate content levelBeginner to intermediate
800 pages
30h 12m
English
O'Reilly Media, Inc.
Content preview from Programming iOS 10

Chapter 7. Scroll Views

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:

  • It knows how to shift its bounds origin in response to the user’s gestures.

  • It provides scroll indicators whose size and position give the user a clue as to the content’s size and position.

  • It can enforce paging, whereby the user can scroll only by a fixed amount.

  • It supports zooming, so that the user can resize the content with a pinch gesture.

  • It provides a plethora of delegate methods, so that your code knows exactly how the user is scrolling and zooming.

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 already knows how far it should be allowed to slide its subviews downward and rightward ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming iOS 12

Programming iOS 12

Matt Neuburg
Programming iOS 11

Programming iOS 11

Matt Neuburg
Programming iOS 13

Programming iOS 13

Matt Neuburg

Publisher Resources

ISBN: 9781491970157Errata Page