Latest 0.0.1
Homepage https://github.com/jberlana/JBParallaxCell
License MIT
Platforms ios 6.0, requires ARC
Authors

iOS Parallax effect on images of UITableViewCell

The goal of this project is to create a parallax effect on a UIImageView on a UITableViewCell when the table scrolls.

This code has been created originally to provide a parallax effect on meets‘s discover tab.

Download the app and test it for free! Feedback is welcome!

Documentation

On your UITableViewCell

  1. Put the parallaxImageView inside a UIView with clipsToBounds = YES; with some offest.
  2. Add this function to calculate the image offset when the UITableView scrolls.
- (void)cellOnTableView:(UITableView *)tableView didScrollOnView:(UIView *)view
{
    CGRect rectInSuperview = [tableView convertRect:self.frame toView:view];

    float distanceFromCenter = CGRectGetHeight(view.frame)/2 - CGRectGetMinY(rectInSuperview);
    float difference = CGRectGetHeight(self.parallaxImage.frame) - CGRectGetHeight(self.frame);
    float move = (distanceFromCenter / CGRectGetHeight(view.frame)) * difference;

    CGRect imageRect = self.parallaxImage.frame;
    imageRect.origin.y = -(difference/2)+move;
    self.parallaxImage.frame = imageRect;
}

On your UITableViewDelegate add this function.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // Get visible cells on table view.
    NSArray *visibleCells = [self.tableView visibleCells];

    for (JBParallaxCell *cell in visibleCells) {
        [cell cellOnTableView:self.tableView didScrollOnView:self.view];
    }
}

And that is all, you can use the demo project to see how everithig works together.

meets, create and discover plans with your friends.

Latest podspec

{
    "name": "JBParallaxCell",
    "version": "0.0.1",
    "summary": "This project provides a parallax effect on a `UIImageView` on a `UITableViewCell` when the table scrolls.",
    "homepage": "https://github.com/jberlana/JBParallaxCell",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Javier Berlana": "[email protected]"
    },
    "social_media_url": "http://twitter.com/jberlana",
    "source": {
        "git": "[email protected]:jberlana/JBParallaxCell.git",
        "tag": "0.0.1"
    },
    "platforms": {
        "ios": "6.0"
    },
    "source_files": "JBParallaxCell.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This