CABasicAnimation 和 CASpringAnimation
CABasicAnimation基本動(dòng)畫
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"];
basicAnimation.duration = 0.5;//一次動(dòng)畫時(shí)間
basicAnimation.fromValue = @(self.buttonSecond.center.x); //起始位置
basicAnimation.toValue = @(self.buttonSecond.center.x-30); //結(jié)束位置
basicAnimation.repeatCount = HUGE_VALL; //次數(shù)
basicAnimation.repeatDuration = 3; //總的動(dòng)畫時(shí)間
//動(dòng)畫完成后蠢沿,不回到初始位置
basicAnimation.removedOnCompletion = NO;
basicAnimation.fillMode = kCAFillModeForwards;
//動(dòng)畫移動(dòng)方式
basicAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[self.buttonSecond.layer addAnimation:basicAnimation forKey:@"animationkey"];
CASpringAnimation彈簧動(dòng)畫
CASpringAnimation是繼承CABasicAnimation
CAKeyframeAnimation
CAKeyframeAnimation *animaton = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
animaton.values = @[@(M_PI_4), @(M_PI_2), @(M_PI_4 * 3), @(M_PI)]; //關(guān)鍵幀
animaton.keyTimes = @[@0.2 ,@0.5 ,@0.7, @0.0]; //幀執(zhí)行時(shí)間點(diǎn) 0~1
animaton.rotationMode = kCAAnimationRotateAutoReverse; //方向
animaton.duration = 3.0f;//每次動(dòng)畫的時(shí)間
animaton.repeatCount = HUGE_VALL;
animaton.path = bezierPath.CGPath;
[self.buttonSecond.layer addAnimation:animaton forKey:@"keyframeAnimation"];
CAAnimationGroup
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.animations = @[basicAnimation,animaton];
animationGroup.duration = 3.0;
animationGroup.repeatCount = 5.0;
[self.buttonSecond.layer addAnimation:animationGroup forKey:@"animationGroup"];
轉(zhuǎn)場(chǎng)動(dòng)畫CATransition
CATransition *caTransition = [CATransition animation];
caTransition.duration = 1.0;
caTransition.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];//時(shí)間函數(shù)
caTransition.type = kCATransitionPush;//切換風(fēng)格
caTransition.subtype = kCATransitionFromTop;//方向
[self.buttonSecond.layer addAnimation:caTransition forKey:@"caTransition"];
仿射CGAffineTransform
CGAffineTransformMake(a, b, c, d, tx, ty)
CGAffineTransformMake(1, 0, 0, 1, 0, 0) //默認(rèn)值
CGAffineTransformMakeRotation(CGFloat angle) 旋轉(zhuǎn)
CGAffineTransformMakeScale(CGFloat sx, CGFloat sy) 縮放
CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty) 位移
- 混合
CGAffineTransformRotate(CGAffineTransform t, CGFloat angle) CGAffineTransformScale(CGAffineTransform t, CGFloat sx, CGFloat sy) CGAffineTransformTranslate(CGAffineTransform t, CGFloat tx, CGFloat ty)
3D轉(zhuǎn)換
CATransform3DMakeRotation(CGFloat angle, CGFloat x, CGFloat y, CGFloat z)
CATransform3DMakeScale(CGFloat sx, CGFloat sy, CGFloat sz) CATransform3DMakeTranslation(Gloat tx, CGFloat ty, CGFloat tz)
貝塞爾曲線UIBezierPath