logo

How to create Pulse style scrolling with a Horizontal UITableView (Including Bounce!!)

Alright, this is actually really simple.

You would think this would work

Create your main UITableView – then in each cell create another UITableView and apply a transform of 90° and you’re good.  But UITableView’s don’t work like that – you end up losing bouncing horizontally on your internal UITableView’s and there is seemingly no solution, but it’s easy.

Wrap your Cell’s UITableView in a UIScrollView. – [scrollView addSubview:tableView]

Bouncing will work now.  (I use EasyTableView – https://github.com/alekseyn/EasyTableView)

  1. Andy Shephard

    Brandon, I can’t thank you enough for your solution. I’ve been spending quite some time trying to think of solutions (bounds editing, adding additional blank cells either side of the table).

    Finally, I can move onto other parts of my project now!

    Thanks again,
    Andy.

  2. Thomas Rued

    Hi Brandon,

    Thanks for the tip!

    However to make the bounce work with my code I had to explicitly enable bounces on both the scrollview and the tableview.
    Thought it could be worth mentioning for other readers! 🙂

    Cheers
    Thomas

    ++++++
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 19, 320, 100)];
    self.scrollView.contentSize = CGSizeMake(320, 100);
    self.scrollView.bounces = YES;
    self.scrollView.alwaysBounceHorizontal = YES;
    [self addSubview:self.scrollView];
    .
    .
    .
    self.horizontalTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 320)];
    self.horizontalTableView.bounces = YES;
    self.horizontalTableView.alwaysBounceVertical = YES;
    self.horizontalTableView.transform = CGAffineTransformMakeRotation(-M_PI * 0.5);
    .
    .

  3. Vuk Nikolić

    Wow, thanks, I’ve been looking for a solution for this problem.
    I can believe that it was so easy. Thanks 🙂

  4. IanFan

    Just love it, thank you so much!
    Simple way and the Best solution.

  5. admin

    You’re welcome!

  6. Alex

    Hello,
    mmm.. unable to make it work…
    My first UITableView displays a subclass of UItableViewCells – call it cellA –

    CellA, subclass of UITableViewCell, have a UITableView, call it TB, as a property, displaying cellB. TB is added as a subview of CellA instances: [cellA addSubView:self.TB]

    the UIscrollview, should wrap:
    TB or CellA ? should the scrollview content be the size of TB height ?
    is there any advice you could share ?
    thanks in advance !

Leave a Reply

*

captcha *