标签:
//创建对象
CABasicAnimation *anim = [CABasicAnimation animation];
// keyPath决定了执行怎样的动画, 调整哪个属性来执行动画
anim.keyPath = @"position";
// toValue : 最终变成什么值
// byValue : 增加多少值
anim.byValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
anim.duration = 1.5;//执行动画的时间
动画执行完,图层又会回到原来的地方,下面两句话是不让图层回到原来的地方
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
[self.layer addAnimation:anim forKey:nil];//把动画添加到图层上面 后面的forKey是移除动画的时候使用
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"bounds";
anim.byValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 100, 100)];
anim.duration = 1.5;
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
[self.layer addAnimation:anim forKey:nil];
CABasicAnimation *anim = [CABasicAnimation animation];
anim.keyPath = @"transform";
anim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 1, -1, 0)];
anim.duration = 1.5;
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
[self.layer addAnimation:anim forKey:nil];
【iOS开发-动画】CABasicAnimation实现动画
标签:
原文地址:http://blog.csdn.net/ttf1993/article/details/46441745