rootcoder
rootcoder

Reputation: 187

UITableViewCell bend animations while scrolling

I need to create a table view animation like the image below while scrolling , But I have very little idea on animations. And also I need to make the selected cell to animate by going inwards and disappear while the cell above and below closes( like the animations done while deleting a Text message in iPhone). TableCell

Upvotes: 0

Views: 2877

Answers (1)

seo
seo

Reputation: 1967

You have to hijack the scrollView (Add yourself as a ScrollViewDelegate alongside TableViewDelegate) and the table view will automatically forward scrollview events along side tableview events.

(self.tableView.delegate = self) is really talking to both

<UIScrollViewDelegate, UITableViewDelegate>

I have a helper function in the example that also calculates distance to the top of the cell.

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSArray *rows = [self.tableView indexPathsForVisibleRows];
    for (NSIndexPath *path in rows) {
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path];
        float percent = [self cellDistanceAsPercentageFromTableViewCenterAtRow:cell];
        cell.layer.sublayerTransform = CATransform3DMakeScale(percent, percent, 1);
    }
}
//Calculate distance of the cell as a percentage from the bottom of the actual visible contentView
-(float)cellDistanceAsPercentageFromTableViewCenterAtRow:(UITableViewCell *)cell {
    float position = cell.frame.origin.y;

    float offsetFromTop = self.tableView.contentOffset.y;

    float percentFromBottom = (position-offsetFromTop+ROW_HEIGHT)/self.tableView.frame.size.height;
    percentFromBottom = MIN(MAX(percentFromBottom, 0), 1);

    return percentFromBottom;
}

Upvotes: 3

Related Questions