CABasicAnimation基础

简单使用


CABasicAnimation *positionAnima = [CABasicAnimation animationWithKeyPath:@"position.y"];
positionAnima.duration = 0.8;
positionAnima.fromValue = @(self.imageView.center.y);
positionAnima.toValue = @(self.imageView.center.y-30);
positionAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
positionAnima.repeatCount = HUGE_VALF;//永不停止
positionAnima.repeatDuration = 2;

//下面两句代码可以防止动画结束后回到初始状
positionAnima.removedOnCompletion = NO;
positionAnima.fillMode = kCAFillModeForwards;
//END

[self.imageView.layer addAnimation:positionAnima forKey:@"AnimationMoveY"];

参考

参考链接一
参考链接二

你可能感兴趣的:(CABasicAnimation基础)