CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(0, 50, 100, 100);
layer.backgroundColor = [UIColor redColor].CGColor;
UIButton *btna = [[UIButton alloc]init];
btna.layer.frame =CGRectMake(0, 50, 100, 100);
// 终点位置
CGPoint endPosition = CGPointMake(layer.position.x, layer.position.y + 200);
// 动画
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [NSValue valueWithCGPoint:layer.position];
animation.toValue = [NSValue valueWithCGPoint:endPosition];
animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.00 :0.00 :1.00 :1.00];
layer.position = endPosition;
animation.duration = 1.f;
// 添加动画
[layer addAnimation:animation forKey:nil];
// 添加layer
[self.view.layer addSublayer:layer];
工具截图:
2016-01-27 15_42_00.gif 2016-01-27 15_48_45.gif