CABasicAnimation-平移

来源:互联网 发布:centos 打不了中文 编辑:程序博客网 时间:2024/04/27 22:46
//平移- (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];}
0 0
原创粉丝点击