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 full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

  5. How to UIScrollView
    Tuesday, 8 May, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. contentInset
    Tuesday, 8 May, 12

    View full-size slide

  10. contentOffset
    Tuesday, 8 May, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  16. Demo: Paging
    Tuesday, 8 May, 12

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide