码迷,mamicode.com
首页 > 移动开发 > 详细

iOS Layer CABasicAnimation

时间:2015-04-23 19:29:40      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

    CALayer *layer = [CALayer layer];

    layer.delegate = self;

    layer.bounds = CGRectMake(0, 0, 100, 100);

    layer.position = CGPointMake(100, 100);

    layer.anchorPoint = CGPointZero;

    layer.backgroundColor = [UIColor blackColor].CGColor;

    [layer setNeedsDisplay];

    [self.view.layer addSublayer:layer];

 

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx

{

    CGContextSetRGBFillColor(ctx, 1.0, 0, 0, 1.0);

    CGContextAddRect(ctx, CGRectMake(0, 0, 20, 20));

    CGContextFillPath(ctx);

} 

 

    CABasicAnimation *basicAnimation = [CABasicAnimation animation];

    basicAnimation.keyPath = @"position";

    basicAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];

    basicAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];

    basicAnimation.duration = 1.0;

    

    basicAnimation.removedOnCompletion = NO;//动画执行完以后不要删除动画

    basicAnimation.fillMode = kCAFillModeForwards;//保持最新的状态

    

    [self.layer addAnimation:basicAnimation forKey:nil]; 

iOS Layer CABasicAnimation

标签:

原文地址:http://www.cnblogs.com/hanjian/p/4451387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!