Last active
August 29, 2015 14:16
-
-
Save iosdevzone/7152d3d6212c2b71761e to your computer and use it in GitHub Desktop.
Bezier curve animation. See https://dribbble.com/shots/1950331-Interactive-shapes-iOS-demo?list=searches&offset=11
This file contains 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)drawRect:(CGRect)rect { | |
[[UIColor lightGrayColor] setFill]; | |
[[UIColor darkGrayColor] setStroke]; | |
UIBezierPath *path = [[UIBezierPath alloc] init]; | |
CGPoint touchPoint = [self.lastTouch locationInView:self]; | |
CGFloat y0 = self.bounds.origin.y; | |
CGFloat weight = 0.75; // Vary from 0 - 1. Values closed to 1 are more pointy. | |
CGFloat y1 = y0 + (touchPoint.y - y0) * weight; // between top of screen and touch | |
CGFloat y2 = touchPoint.y; | |
CGFloat y4 = CGRectGetMaxY(self.bounds); | |
CGFloat y3 = y4 - (y4 - y2) * weight; // between touch point and bottom of screen | |
CGFloat x0 = self.bounds.origin.y; | |
CGFloat x1 = touchPoint.x; | |
[path moveToPoint:CGPointZero]; | |
[path addCurveToPoint:touchPoint controlPoint1:CGPointMake(x0, y1) controlPoint2:CGPointMake(x1, y1)]; | |
[path addCurveToPoint:CGPointMake(x0, y4) controlPoint1:CGPointMake(x1, y3) controlPoint2:CGPointMake(x0, y3)]; | |
[path closePath]; | |
[path fill]; | |
[path stroke]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bezier curve animation. See https://dribbble.com/shots/1950331-Interactive-shapes-iOS-demo?list=searches&offset=11