CABasicAnimation-平移
//平移
- (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];
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: Linux下远程登录阿里云服务器
- 下一篇: linden