Skip to content

Instantly share code, notes, and snippets.

@joelklabo
Created February 15, 2013 06:00
Show Gist options
  • Save joelklabo/4958776 to your computer and use it in GitHub Desktop.
Save joelklabo/4958776 to your computer and use it in GitHub Desktop.
//
// Shape_04ViewController.m
// Shape_04
//
// Created by test on 9/4/09.
// Copyright __MyCompanyName__ 2009. All rights reserved.
//
#import "Shape_04ViewController.h"
@implementation Shape_04ViewController
- (void)loadView
{
UIView *appView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
appView.backgroundColor = [UIColor blackColor];
self.view = appView;
[appView release];
rootLayer = [CALayer layer];
rootLayer.frame = self.view.bounds;
[self.view.layer addSublayer:rootLayer];
CGPoint center = self.view.center;
//Letter path
letterTiltedLeft = CGPathCreateMutable();
CGPathMoveToPoint(letterTiltedLeft, nil, 55 , 55);
CGPathAddLineToPoint(letterTiltedLeft, nil, 55, 130);
CGPathAddLineToPoint(letterTiltedLeft, nil, 165, 130);
CGPathAddLineToPoint(letterTiltedLeft, nil, 165, 55);
CGPathAddLineToPoint(letterTiltedLeft, nil, 53, 55);
CGPathCloseSubpath(letterTiltedLeft);
//Letter tilted left path
letterTiltedLeft = CGPathCreateMutable();
CGPathMoveToPoint(letterTiltedLeft, nil, 55 , 65);
CGPathAddLineToPoint(letterTiltedLeft, nil, 55, 120);
CGPathAddLineToPoint(letterTiltedLeft, nil, 165, 130);
CGPathAddLineToPoint(letterTiltedLeft, nil, 165, 55);
CGPathAddLineToPoint(letterTiltedLeft, nil, 53, 65);
CGPathCloseSubpath(letterTiltedLeft);
//Letter tilted right path
letterTiltedRight = CGPathCreateMutable();
CGPathMoveToPoint(letterTiltedRight, nil, 55 , 55);
CGPathAddLineToPoint(letterTiltedRight, nil, 55, 130);
CGPathAddLineToPoint(letterTiltedRight, nil, 165, 120);
CGPathAddLineToPoint(letterTiltedRight, nil, 165, 65);
CGPathAddLineToPoint(letterTiltedLeft, nil, 53, 55);
CGPathCloseSubpath(letterTiltedRight);
//Create Shape
shapeLayer = [CAShapeLayer layer];
shapeLayer.path = letterTiltedRight;
UIColor *fillColor = [UIColor colorWithHue:0.584 saturation:0.8 brightness:0.9 alpha:1.0];
shapeLayer.fillColor = fillColor.CGColor;
UIColor *strokeColor = [UIColor colorWithHue:0.557 saturation:0.55 brightness:0.96 alpha:1.0];
shapeLayer.strokeColor = strokeColor.CGColor;
shapeLayer.lineWidth = 2.0;
shapeLayer.fillRule = kCAFillRuleNonZero;
[rootLayer addSublayer:shapeLayer];
[self performSelector:@selector(startAnimation) withObject:nil afterDelay:1.5];
}
-(void)startAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = 2.0f;
animation.repeatCount = HUGE_VALF;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = (id)letterTiltedRight;
animation.byValue = (id)letterPath;
animation.toValue = (id)letterTiltedLeft;
[shapeLayer addAnimation:animation forKey:@"animatePath"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc
{
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment