Make UITableView stop in certain position?

Discussion in 'iOS Programming' started by CharleyParker, Apr 29, 2009.

  1. CharleyParker macrumors newbie

    Apr 29, 2009
    I'm trying to display a series of full screen images in a UITableView (because I want to allow the user to be able to swipe through several at a time, and I want them to have that springy bounce).

    I have a table set up (in landscape view) with full-screen size cells (480x320), and I'm loading the cells with images from an array. So far so good.

    The problem is that I want the full-screen size cells to line up with the window when the TableView comes to a stop. The default seems to be that the TableView stops where it will, with no regard for the window or view coordinates, I suppose on the assumption that the cells will always be considerably smaller than the window.

    Is there a way to make it coast to a stop so the full-screen sized cells line up with the window (or even have it adjust its position after stopping)?

    I looked into using a UIScrollView with pagingEnabled to accomplish the same thing, but this seems to be limited to scrolling one page at a time. All of the examples I've seen seem limited to a single page per swipe. Maybe there a way to let a UIScrollView scroll through multiple pages with a single fast swipe?

    I'm trying to adapt a UITableView specifically to get that behavior. I want to let the user move past several images at a time with a fast swipe, or page through them individually with slower motions.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Since UITableView is just a subclass of UIScrollView, why not try setting pagingEnabled on your table view?
  3. djcraze macrumors regular


    Jul 3, 2007
    UIPickerView maybe? :-\, just an idea. IDK if the interface of that would look good in your application though.
  4. Niiro13 macrumors 68000

    Feb 12, 2008
    Yes, it's true that the examples that use paging are only one page at a time.

    If you look at the code, however, you'll notice that you can modify scrollview did scroll in order to set paging only when the swipe is quick.

    It's approximately the same way I used in order to get horizontal paging but vertical scrolling.

    In fact you could set paging to more than one page if you just tell it to scroll more than one. But I think setting normal scrolling then set the paging when it starts slowing down is better.
  5. CharleyParker thread starter macrumors newbie

    Apr 29, 2009
    Thanks, everyone, for the suggestions. I'll try them in turn and report back.

    I looked into UIPickerView because it does something else I want to do with this, which is have the array of images loop back on themselves so it's continuous in either direction. The UIPickerView does that, as well as having the right physics, but it seems limited to its faux-cylinder appearance. (Though all of my information about these features is sketchy and based on limited experience.)

Share This Page