Skip to content

Commit

Permalink
Smooth the pan gesture.
Browse files Browse the repository at this point in the history
  • Loading branch information
André Schneider committed Jul 17, 2014
1 parent a29b485 commit 7aed4d0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Popping/FoldView.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ - (BOOL)isLocation:(CGPoint)location inView:(UIView *)view;
@property(nonatomic) UIImageView *backView;
@property(nonatomic) CAGradientLayer *bottomShadowLayer;
@property(nonatomic) CAGradientLayer *topShadowLayer;
@property(nonatomic) NSUInteger initialLocation;
@end

@implementation FoldView
Expand Down Expand Up @@ -123,6 +124,10 @@ - (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:self];

if (recognizer.state == UIGestureRecognizerStateBegan) {
self.initialLocation = location.y;
}

if ([[self.topView.layer valueForKeyPath:@"transform.rotation.x"] floatValue] < -M_PI_2) {
self.backView.alpha = 1.0;
[CATransaction begin];
Expand All @@ -136,17 +141,18 @@ - (void)handlePan:(UIPanGestureRecognizer *)recognizer
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
self.bottomShadowLayer.opacity = location.y/CGRectGetHeight(self.bounds);
self.topShadowLayer.opacity = location.y/CGRectGetHeight(self.bounds);
CGFloat opacity = (location.y-self.initialLocation)/(CGRectGetHeight(self.bounds)-self.initialLocation);
self.bottomShadowLayer.opacity = opacity;
self.topShadowLayer.opacity = opacity;
[CATransaction commit];
}

if ([self isLocation:location inView:self]) {
CGFloat conversionFactor = -M_PI / CGRectGetHeight(self.bounds);
CGFloat conversionFactor = -M_PI / (CGRectGetHeight(self.bounds) - self.initialLocation);
POPBasicAnimation *rotationAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerRotationX];

rotationAnimation.duration = 0.01;
rotationAnimation.toValue = @(location.y*conversionFactor);
rotationAnimation.toValue = @((location.y-self.initialLocation)*conversionFactor);
[self.topView.layer pop_addAnimation:rotationAnimation forKey:@"rotationAnimation"];
} else {
recognizer.enabled = NO;
Expand Down

0 comments on commit 7aed4d0

Please sign in to comment.