-
-
Save macressler/e72f998c4cc4dc2577db to your computer and use it in GitHub Desktop.
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
- (void)dragged:(UIPanGestureRecognizer *)gestureRecognizer | |
{ | |
CGFloat xDistance = [gestureRecognizer translationInView:self].x; | |
CGFloat yDistance = [gestureRecognizer translationInView:self].y; | |
switch (gestureRecognizer.state) { | |
case UIGestureRecognizerStateBegan:{ | |
self.originalPoint = self.center; | |
break; | |
}; | |
case UIGestureRecognizerStateChanged:{ | |
CGFloat rotationStrength = MIN(xDistance / 320, 1); | |
CGFloat rotationAngel = (CGFloat) (2*M_PI/16 * rotationStrength); | |
CGFloat scaleStrength = 1 - fabsf(rotationStrength) / 4; | |
CGFloat scale = MAX(scaleStrength, 0.93); | |
CGAffineTransform transform = CGAffineTransformMakeRotation(rotationAngel); | |
CGAffineTransform scaleTransform = CGAffineTransformScale(transform, scale, scale); | |
self.transform = scaleTransform; | |
self.center = CGPointMake(self.originalPoint.x + xDistance, self.originalPoint.y + yDistance); | |
[self updateOverlay:xDistance]; | |
break; | |
}; | |
case UIGestureRecognizerStateEnded: { | |
[self resetViewPositionAndTransformations]; | |
break; | |
}; | |
case UIGestureRecognizerStatePossible:break; | |
case UIGestureRecognizerStateCancelled:break; | |
case UIGestureRecognizerStateFailed:break; | |
} | |
} | |
- (void)updateOverlay:(CGFloat)distance | |
{ | |
if (distance > 0) { | |
self.overlayView.mode = GGOverlayViewModeRight; | |
} else if (distance <= 0) { | |
self.overlayView.mode = GGOverlayViewModeLeft; | |
} | |
CGFloat overlayStrength = MIN(fabsf(distance) / 100, 0.4); | |
self.overlayView.alpha = overlayStrength; | |
} | |
- (void)resetViewPositionAndTransformations | |
{ | |
[UIView animateWithDuration:0.2 | |
animations:^{ | |
self.center = self.originalPoint; | |
self.transform = CGAffineTransformMakeRotation(0); | |
self.overlayView.alpha = 0; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment