animaiton各种好玩动画·3

第一种,渐变色变化
CAGradientLayer *gradient = [CAGradientLayer layer];
CGRect rect = CGRectMake(200, 100, 100, 100);
gradient.frame = rect;
gradient.colors = [NSArray arrayWithObjects:(id)[UIColor blueColor].CGColor,
(id)[UIColor whiteColor].CGColor,
nil];
[self.view.layer insertSublayer:gradient atIndex:0];

第二种,透明-显示
CABasicAnimation *opAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
opAnim.duration = 3.0;
opAnim.fromValue = [NSNumber numberWithFloat:.25];
opAnim.toValue = [NSNumber numberWithFloat:1.0];
opAnim.cumulative = NO;//不累积
opAnim.repeatCount = MAXFLOAT;
[_planeView.layer addAnimation:opAnim forKey:@"animateOpacity"];
第三种,移动位置
CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(10, 200);
CABasicAnimation *moveAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
moveAnim.duration = 2.0;
moveAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTransform)];
moveAnim.removedOnCompletion = NO;//必须要设置为no,用CAAnimation必须这样设置。
moveAnim.cumulative = YES;

moveAnim.fillMode = kCAFillModeBoth;
[_planeView.layer addAnimation:moveAnim forKey:@"animateTransform"];

第四种,组合移动位置
CAKeyframeAnimation *opAnim = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
opAnim.duration = 6.0;
opAnim.values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.25], [NSNumber numberWithFloat:0.75], [NSNumber numberWithFloat:1.0], nil];
opAnim.keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];
[_planeView.layer addAnimation:opAnim forKey:@"animateOpacity"];

CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(180, 200);
CABasicAnimation *moveAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
moveAnim.duration = 6.0;
moveAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTransform)];
[_planeView.layer addAnimation:moveAnim forKey:@"animateTransform"];

你可能感兴趣的:(animaiton各种好玩动画·3)