本文主要是介绍CABasicAnimation-平移,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//平移
- (void)animationTranslate{//创建layerCALayer *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-平移的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!