Fun With UIScrollView

It enables users to scroll within that content by making swiping gestures, and to zoom in and back from portions of the content by making pinching gestures.

Reading Time 2 mins

The following is a guest post by Dulio Denis and originally appeared on his blog. Dulio is currently in the iOS-000 class at The Flatiron School. You can follow him on Twitter here.

Today, at Flatiron, I presented a Tech Talk that provided a tour of UIScrollView.  The UIScrollView class provides support for displaying content that is larger than the size of the application’s window. It enables users to scroll within that content by making swiping gestures, and to zoom in and back from portions of the content by making pinching gestures. On a phone, and even an iPad, this is crucial.

UIScrollView is the superclass of several UIKit classes including:

  • UITableView

  • UITextView

The UIScrollView class can have a delegate that must adopt the UIScrollViewDelegate protocol. For zooming and panning to work, the delegate must implement both viewForZoomingInScrollView: and scrollViewDidEndZooming:withView:atScale:; in addition, the maximum (maximumZoomScale) and minimum (minimumZoomScale) zoom scale must be different.

Apple is a Heavy User of UIScrollView and its the first thing a user sees in Apple’s Nesting of Scroll Views usage at the Lock Screen. Some notable examples are:

  • iOS 7 Lock Screen: Scroll To Unlock Two Page Scroll View

  • Notifications are an Embedded Vertical Scroll View where Each Notification is an Embedded Horizontal Scroll View

  • Spotlight

  • Multitasking

  • Calendar

  • Clock

  • the list goes on and on

I then presented some examples of my own attempts at a cross directional UIScrollView implementation like those seen in the MLB AtBat App, Facebook, or Pulse.  In my journeys I also wanted to implement paging of images in my examples and I encountered the UIPageViewController class which was introduced in iOS 5 as a mechanism to implement a page turning style of user interface in iOS applications. It is the successor to the UIPageControl class and as such is easier to use.  I showcased the Path App as utilizing a Tutorial that can easily be done with this class and my own attempt to implement it.

Another area of note is the Apple Apple PhotoScroller Sample App iOS Developer Library sample project which demonstrates the use of embedded UIScrollViews and CATiledLayer to create a rich user experience for displaying and paginating photos that can be individually panned and zoomed. This sample goes over the top with CATiledLayer which is used to increase the performance of paging, panning, and zooming with high-resolution images or large sets of photos.

Finally, after reviewing GitHub I found a great open source (MIT License) project by Andrey Tarantsov of Russia called ATPagingView.  This is a great library of code for exactly what we toured in the talk: implementing timed horizontal scrolling of several images which take up most of the screen. You have to implement the timer yourself that switches the view, and it does have user enabled switching as well.

This was my first Tech Talk and I look forward now to starting my CapStone project.

Disclaimer: The information in this blog is current as of November 12, 2013. Current policies, offerings, procedures, and programs may differ.

About Flatiron School

More articles by Flatiron School