Giter VIP home page Giter VIP logo

jbparallaxcell's Introduction

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.

image

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.###

jbparallaxcell's People

Contributors

ehlersd avatar esttorhe avatar jberlana avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jbparallaxcell's Issues

UITableViewController support

I can't have it working on a UITableViewController class, only in a UITableView inside a UIViewController as shown in the example. Is there a way to have it working directly from a UITableViewController

Table Scrolling Issue with navigation bar

"JBParallaxCell" is working fine with smooth scrolling if UIViewController does not have Navigation Bar, while if navigation bar is there on UIViewController. In that case scrolling doesn't working fine and stuck a lot. Which does not looks good. I tried your sample code as well and when I embedded ViewController with Navigation Controller with Navigation Bar displayed, sample code also start stuck behavior while scrolling.
Do you have an idea, why it happened, and how can we resolve this ?

Problem of segueing the view

The JBParallaxCell are work very well in single view.
But if I use the JBParallaxCell for main view and segue into detailView, then return form detailview to JBParallaxCell and it will reset the imageView position until you scroll the view.

collectionView

If I have collcetionView inside tableVIew. collcetionViewCell have imageView. How can I use it?

Pod not working

Your pod doesn't work, here's the Cocoapods log:

    -> Installing JBParallaxCell (0.0.1)
     > Git download
     > Git download
         $ /usr/local/bin/git clone [email protected]:jberlana/JBParallaxCell.git /var/folders/vy/_kcg_9p14gl_1kv8d03qs3bw0000gn/T/d20150601-64138-1hzcvpp --single-branch --depth 1
         --branch 0.0.1
         Cloning into '/var/folders/vy/_kcg_9p14gl_1kv8d03qs3bw0000gn/T/d20150601-64138-1hzcvpp'...
         Permission denied (publickey).
         fatal: Could not read from remote repository.

         Please make sure you have the correct access rights
         and the repository exists.

    [!] Error installing JBParallaxCell
    [!] /usr/local/bin/git clone [email protected]:jberlana/JBParallaxCell.git /var/folders/vy/_kcg_9p14gl_1kv8d03qs3bw0000gn/T/d20150601-64138-1hzcvpp --single-branch --depth 1 --branch 0.0.1

    Cloning into '/var/folders/vy/_kcg_9p14gl_1kv8d03qs3bw0000gn/T/d20150601-64138-1hzcvpp'...

    Permission denied (publickey).

    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.