Last active
June 9, 2017 23:18
-
-
Save ynechaev/8123997 to your computer and use it in GitHub Desktop.
UITableViewCell popular animation (flipping around Y axis, depending on scroll direction)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know why the cell view overlaps the another one if let cell.layer.anchorPoint = CGPointMake(0.5, 0) when scrolling?