Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Working With Scroll Views

Working With Scroll Views

Ash Furrow

March 08, 2012
Tweet

More Decks by Ash Furrow

Other Decks in Programming

Transcript

  1. Working with
    Scroll Views
    Ash Furrow
    Tuesday, 8 May, 12

    View Slide

  2. What is a scroll view?
    • Subclass of UIView
    • A view which scrolls
    • Sometimes zooms
    Tuesday, 8 May, 12

    View Slide

  3. What is a scroll view?
    • Subclass of UIView
    • A view which scrolls
    • Sometimes zooms
    UIView
    UIScrollView
    Tuesday, 8 May, 12

    View Slide

  4. OK, what does
    “scroll” mean?
    • A container view that lets its subviews
    move around
    • Maps
    • Home screen
    • Table view
    • Most things that move in iOS
    Tuesday, 8 May, 12

    View Slide

  5. How to UIScrollView
    Tuesday, 8 May, 12

    View Slide

  6. How to UIScrollView
    • Create scroll view, either in xib or
    programmatically
    • Add subviews
    • ???
    • Profit!
    Tuesday, 8 May, 12

    View Slide

  7. How to UIScrollView
    • Create scroll view, either in xib or
    programmatically
    • Add subviews
    • ???
    • Profit!
    • ʵ Set contentSize
    Tuesday, 8 May, 12

    View Slide

  8. contentSize
    • Defines the
    scrollable region
    • CGSize
    • Large
    contentSize
    values don’t
    adversely affect
    performance
    Tuesday, 8 May, 12

    View Slide

  9. contentInset
    Tuesday, 8 May, 12

    View Slide

  10. contentOffset
    Tuesday, 8 May, 12

    View Slide

  11. Demo: Basic Scroll View
    Tuesday, 8 May, 12

    View Slide

  12. Scrolling
    • With Fingers!
    • Receive delegate callbacks (next slide)
    • Programmatically
    • to top
    • to new contentOffset
    • to new rectangle
    Tuesday, 8 May, 12

    View Slide

  13. Interesting Properties
    • delaysContentTouches
    • scrollview gesture recognizers
    • bounces
    • alwaysBouncesVertical
    • alwaysBouncesHorizontal
    • scroll indicators (inset & style)
    • pagingEnabled
    Tuesday, 8 May, 12

    View Slide

  14. Zooming
    • I am not an expert at zooming scroll views
    • Different approaches
    • Watch the WWDC videos
    Tuesday, 8 May, 12

    View Slide

  15. UIScrollViewDelegate
    • Tracking
    • Dragging
    • Decelerating
    • Zooming
    • contentOffset change
    Tuesday, 8 May, 12

    View Slide

  16. Demo: Paging
    Tuesday, 8 May, 12

    View Slide

  17. YO, DAWG.
    I HEARD YOU LIKE SCROLLING.
    Tuesday, 8 May, 12

    View Slide

  18. UITableViewDelegate
    • UITableView subclasses UIScrollView
    • Captures UIScrollViewDelegate
    callbacks
    Tuesday, 8 May, 12

    View Slide

  19. Performance
    • UIScrollView Scales with subviews
    • Not with contentSize
    • UIImage will kill your memory footprint
    Tuesday, 8 May, 12

    View Slide

  20. Delegate flowcharts
    • UIScrollViewDelegate is simple
    • Implementing complex behaviour with it
    is not
    Tuesday, 8 May, 12

    View Slide

  21. Subclassing vs
    Delegation
    • Subclassing can break MVC
    • Better for repeated behaviours
    • Delegation can get verbose
    • You’re writing Objective-C, live with it
    Tuesday, 8 May, 12

    View Slide

  22. Demo: Reusing Subviews
    Tuesday, 8 May, 12

    View Slide

  23. Demo: Infinite Scroll
    Tuesday, 8 May, 12

    View Slide

  24. Ash Furrow
    [email protected]
    @ashfurrow
    Podcast: DashDashForce.me
    http://ashfurrow.com/ScrollViewMaterials.zip
    Tuesday, 8 May, 12

    View Slide