CABasicAnimation

//CAKeyframeAnimation关键帧动画之悬浮

- (void)valueKeyframeAni {

CAKeyframeAnimation * ani = [CAKeyframeAnimation animationWithKeyPath:@"position"];

ani.duration = 4.0;

ani.removedOnCompletion = NO;

ani.fillMode = kCAFillModeForwards;

ani.repeatCount = HUGE_VALF;

ani.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

NSValue *value1 = [NSValue valueWithCGPoint:CGPointMake(150, 200)];

NSValue *value2 = [NSValue valueWithCGPoint:CGPointMake(155, 202)];

NSValue *value3 = [NSValue valueWithCGPoint:CGPointMake(150, 205)];

NSValue *value4 = [NSValue valueWithCGPoint:CGPointMake(145, 202)];

NSValue *value5 = [NSValue valueWithCGPoint:CGPointMake(150, 200)];

ani.values = @[value1, value2, value3, value4, value5];

[_view1.layer addAnimation:ani forKey:@"PostionKeyframeValueAni"];

}

//横向拉伸缩放

- (void)animation_width:(UIImageView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contentsRect.size.width"];

animation.fromValue = @(1);

animation.toValue = @(0.5);

animation.repeatCount = HUGE_VALF;

animation.duration = 2.0;

animation.fillMode = kCAFillModeBackwards;

animation.autoreverses = YES;

animation.removedOnCompletion = NO;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[view.layer addAnimation:animation forKey:@"contentsRect.size.width"];

}

//改变透明度

- (void)animation_opacity:(UIImageView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];

animation.fromValue = @(1);

animation.toValue = @(0);

animation.repeatCount = HUGE_VALF;

animation.duration = 2.0;

animation.fillMode = kCAFillModeBackwards;

animation.autoreverses = YES;

animation.removedOnCompletion = NO;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[view.layer addAnimation:animation forKey:@"opacity"];

}

//改变内容

- (void)animation_content:(UIImageView *)image {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"contents"];

animation.toValue = (id)[UIImage imageNamed:@"2.jpg"].CGImage;

animation.repeatCount = HUGE_VALF;

animation.duration = 2.0;

animation.fillMode = kCAFillModeBackwards;

animation.removedOnCompletion = NO;

animation.autoreverses = YES;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[image.layer addAnimation:animation forKey:@"contents"];

}

//背景颜色变化

- (void)animation_bgcolor:(UIView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"backgroundColor"];

animation.fromValue = (id)[UIColor purpleColor].CGColor;

animation.toValue = (id)[UIColor redColor].CGColor;

animation.repeatCount = HUGE_VALF;

animation.duration = 2.0;

animation.fillMode = kCAFillModeBackwards;

animation.removedOnCompletion = NO;

animation.autoreverses = YES;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[view.layer addAnimation:animation forKey:@"backgroundColor"];

}

//圆角动画

- (void)animation_raduis:(UIView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"cornerRadius"];

animation.fromValue = @(0);

animation.toValue = @(50);

animation.repeatCount = HUGE_VALF;

animation.duration = 2.0;

animation.fillMode = kCAFillModeBackwards;

animation.autoreverses = YES;

animation.removedOnCompletion = NO;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[view.layer addAnimation:animation forKey:@"cornerRadius"];

}

//x轴旋转

- (void)animation_rotationx:(UIView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];

animation.fromValue = @(M_PI);

animation.toValue = @(0);

animation.repeatCount = HUGE_VALF;

animation.duration = 2;

animation.autoreverses = YES;

animation.fillMode = kCAFillModeBackwards;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

animation.removedOnCompletion = NO;

[view.layer addAnimation:animation forKey:@"transformX"];

}

//y轴旋转

- (void)animation_rotationy:(UIView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];

animation.fromValue = @(M_PI);

animation.toValue = @(0);

animation.repeatCount = HUGE_VALF;

animation.duration = 2;

animation.autoreverses = YES;

animation.fillMode = kCAFillModeBackwards;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

animation.removedOnCompletion = NO;

[view.layer addAnimation:animation forKey:@"transformY"];

}

//z轴旋转

- (void)animation_rotationz:(UIView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

animation.fromValue = @(M_PI);

animation.toValue = @(0);

animation.repeatCount = HUGE_VALF;

animation.duration = 2;

animation.autoreverses = YES;

animation.fillMode = kCAFillModeBackwards;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

animation.removedOnCompletion = NO;

[view.layer addAnimation:animation forKey:@"transformZ"];

}

//缩放

- (void)animation_x:(UIView *)view {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

animation.fromValue = @(1.0);

animation.toValue = @(0.1);

animation.duration = 2.0;

animation.repeatCount = HUGE_VALF;

animation.removedOnCompletion = NO;

animation.autoreverses = YES;

animation.fillMode = kCAFillModeBackwards;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[view.layer addAnimation:animation forKey:@"translationX"];

}

//中心点平移移动

- (void)animationX:(UIView *)selfView {

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];

animation.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];

animation.duration = 1.0;

animation.removedOnCompletion = NO;

animation.fillMode = kCAFillModeForwards;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[selfView.layer addAnimation:animation forKey:@"animationX"];

}

//x和y都移动

- (void)animationXandY:(UIView *)selfView{

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];

animation.toValue = [NSValue valueWithCGPoint:_view1.center];

animation.duration = 1.0;

animation.removedOnCompletion = NO;

animation.fillMode = kCAFillModeForwards;

animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

animation.delegate = self;

[selfView.layer addAnimation:animation forKey:@"AnimationPosi"];

}

你可能感兴趣的:(CABasicAnimation)