Created
February 15, 2013 06:00
-
-
Save joelklabo/4958776 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
// | |
// 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