Search code examples
iosuitableviewparallax

Parallax Scrolling Effect like TodoMovies 3


I was wondering how I might go about implementing a scrolling parallax effect similar to what is seen in TodoMovies 3?

In TodoMovies 3, the background of (what I think is) a UITableViewCell moves faster than the scrolling of the page, making a really awesome effect.

How would you go about detecting the scroll of the TableView's scrollview and also adjust the background image of the cell in a performant way?

Or is the effect impossible to achieve with UITableView?


Solution

  • I was able to achieve the effect by placing this code in my UITableViewController

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        for (TVTableViewCell *cell in [self.tableView visibleCells]) {
            [cell adjust:(cell.frame.origin.y - scrollView.contentOffset.y)];
        }
    }
    

    And this code in my UITableViewCell

    - (void)adjust:(CGFloat)offset {
        CGRect frame = self.image.frame;
        frame.origin.y = (offset / 10.0);
        self.image.frame = frame;
    }
    

    Modified from oleb.net/blog/2014/05/parallax-scrolling-collectionview. Thanks mustafabesnili for the link.