Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/d88746021b8417b652cd to your computer and use it in GitHub Desktop.
Save baobao/d88746021b8417b652cd to your computer and use it in GitHub Desktop.
CoreAnimationの勉強。 Flashのような描画テスト。
//layer生成
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(0, 0, 20, 20);
layer.backgroundColor = [[UIColor redColor] CGColor];
//layer設定
layer.position = CGPointMake(100, 200);
//枠線カラー
layer.borderColor =[UIColor blueColor].CGColor;
//枠線の太さ
layer.borderWidth = 10;
//addChild
[self.view.layer addSublayer:layer];
//透明度
layer.opacity = 0.5;
//ドロップシャドウの設定
layer.shadowOpacity = 0.8;
//影の形
layer.shadowPath = [UIBezierPath bezierPathWithRect:layer.bounds].CGPath;
//ぼかしの大きさ
layer.shadowRadius = 10;
//offset
layer.shadowOffset = CGSizeMake(4, 4);
//影の色
layer.shadowColor = [UIColor blackColor].CGColor;
CGMutablePathRef path = CGPathCreateMutable();
//パスの最初のポイントをセット
CGPathMoveToPoint(path, NULL, 74, 74);
//座標を追加
CGPathAddCurveToPoint(path, NULL,
74, 200,
100, 200,
200, 420);
//座標を追加
CGPathAddCurveToPoint(path, NULL, 320, 0, 100, 100, 6, 74);
//アニメーションインスタンスを生成
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//2秒かける
animation.duration = 2.0f;
//アニメーションパスを設定
animation.path = path;
//リピート
animation.repeatCount = NSUIntegerMax;
//動きをリバース
animation.autoreverses = YES;
//イージング
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//アニメーション開始
[layer addAnimation:animation forKey:@"aaa"];
@baobao
Copy link
Author

baobao commented Mar 16, 2013

ドロップシャドウを追加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment