动画一般设置的属性有
一、
1.按比例放大缩小 "transform.scale.xy"
2.按位置 "position"
3.按旋转角度 “transform.rotation”
CABasicAnimation* scaleAnimation = [CABasicAnimation
animationWithKeyPath:@"transform.scale.xy"];//设置动画的属性
scaleAnimation.fromValue = @0.0;//设置开始属性值
scaleAnimation.toValue = @1.0;//设置结束属性值
scaleAnimation.duration = 2;//设置动画时间段
二、动画组(CABasicAnimation+CAKeyframeAnimation)
UIView* animationView = [[UIView alloc]initWithFrame:CGRectMake(300,200,200,200)];
animationView.backgroundColor = [UIColoryellowColor];
CAAnimationGroup* _animaTionGroup;
/**
* 动画速度,何时快、慢
* kCAMediaTimingFunctionEaseInEaseOut 先慢 后慢 中间快
* kCAMediaTimingFunctionEaseIn 先慢
* kCAMediaTimingFunctionEaseOut 后慢
* kCAMediaTimingFunctionLinear 匀速
* kCAMediaTimingFunctionDefault 默认
*/
CAMediaTimingFunction* defaultCure = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionDefault];
_animaTionGroup = [CAAnimationGroup animation];
_animaTionGroup.delegate = self;
_animaTionGroup.duration = 2;
_animaTionGroup.removedOnCompletion = YES;
_animaTionGroup.timingFunction = defaultCure;
CABasicAnimation* scaleAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.scale.xy"];
scaleAnimation.fromValue = @0.0;
scaleAnimation.toValue = @1.0;
scaleAnimation.duration = 2;
CAKeyframeAnimation* opencityAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"opacity"];
opencityAnimation.duration = 2;
opencityAnimation.values = @[@0.8,@0.4,@0];
opencityAnimation.keyTimes = @[@0,@0.5,@1];
opencityAnimation.removedOnCompletion = YES;
NSArray* animations = @[scaleAnimation,opencityAnimation];
_animaTionGroup.animations = animations;
_animaTionGroup.repeatCount = 10;
_animaTionGroup.removedOnCompletion = YES;
[animationView.layer addAnimation:_animaTionGroup forKey:nil];
三、动画效果(系统自带:好像只有从左往右的动画效果,其它都没有效果。)
CATransition* animation = [CATransitionanimation];
//动画播放时间
[animation setDuration:2.0f];
//动画效果
/**
* kCATransitionMoveIn 覆盖原图
* kCATransitionFade 淡出
* kCATransitionPush 推出
* kCATransitionReveal底部显出来
* kCATransitionFromRight 动画方向
* kCATransitionFromBottom 动画方向
* kCATransitionFromLeft 动画方向
* kCATransitionFromTop 动画方向
*/
[animation setType:kCATransitionMoveIn];
//动画
[animation setSubtype:kCATransitionFromBottom];
[self.layeraddAnimation:animationforKey:nil];
四、block的动画组
[UIViewanimateKeyframesWithDuration:8.0fdelay:0options:UIViewKeyframeAnimationOptionCalculationModeLinearanimations:^{
[UIViewaddKeyframeWithRelativeStartTime:0.0//相对于6秒所开始的时间(第0秒开始动画)
relativeDuration:1/3.0//相对于6秒动画的持续时间(动画持续2秒)
animations:^{
self.backgroundColor = [UIColorredColor];
}];
[UIViewaddKeyframeWithRelativeStartTime:1/3.0//相对于6秒所开始的时间(第2秒开始动画)
relativeDuration:1/3.0//相对于6秒动画的持续时间(动画持续2秒)
animations:^{
self.backgroundColor = [UIColoryellowColor];
}];
[UIViewaddKeyframeWithRelativeStartTime:2/3.0f//相对于6秒所开始的时间(第4秒开始动画)
relativeDuration:1/3.0//相对于6秒动画的持续时间(动画持续2秒)
animations:^{
self.backgroundColor = [UIColorgreenColor];
}];
} completion:^(BOOL finished) {
[selfrunAnimateKeyframes];
}];