//平移
- (void)animationTranslate{
//创建layer
CALayer *layer =[CALayer layer];
layer.bounds = CGRectMake(0, 0, 100, 100);
layer.position = CGPointMake(100,100);
layer.backgroundColor = [UIColor yellowColor].CGColor;
[self.view.layer addSublayer:layer];
//1.创建动画对象
CABasicAnimation *animation = [CABasicAnimation animation];
//2.设置动画
// keyPath 决定了执行怎样的动画
animation.keyPath = @"position";
// toValue 到达哪个点,byValue是增加多少值,fromValue 从哪个点开始移动
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 200)];
animation.duration = 2;
animation.removedOnCompletion = NO;//动画执行完毕后不删除动画
//保持最新的状态
animation.fillMode = @"forwards";
//3.添加动画
[layer addAnimation:animation forKey:nil];
}
CABasicAnimation-平移
最新推荐文章于 2024-04-11 01:36:21 发布