Skip to content

Instantly share code, notes, and snippets.

@ynechaev
Last active June 9, 2017 23:18
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save ynechaev/8123997 to your computer and use it in GitHub Desktop.
Save ynechaev/8123997 to your computer and use it in GitHub Desktop.
UITableViewCell popular animation (flipping around Y axis, depending on scroll direction)
@interface YourViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UIImageOrientation scrollOrientation;
CGPoint lastPos;
}
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView.isDragging) {
UIView *myView = cell.contentView;
CALayer *layer = myView.layer;
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -1000;
if (scrollOrientation == UIImageOrientationDown) {
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI*0.5, 1.0f, 0.0f, 0.0f);
} else {
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, -M_PI*0.5, 1.0f, 0.0f, 0.0f);
}
layer.transform = rotationAndPerspectiveTransform;
[UIView animateWithDuration:.5 animations:^{
layer.transform = CATransform3DIdentity;
}];
}
}
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
scrollOrientation = scrollView.contentOffset.y > lastPos.y?UIImageOrientationDown:UIImageOrientationUp;
lastPos = scrollView.contentOffset;
}
@scottphc
Copy link

scottphc commented Jan 6, 2016

Do you know why the cell view overlaps the another one if let cell.layer.anchorPoint = CGPointMake(0.5, 0) when scrolling?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment