第一种,撞边框回弹效果
{
CGMutablePathRef starPath = CGPathCreateMutable();
CGPathMoveToPoint(starPath, NULL, 160.0f, 100.0f);
CGPathAddLineToPoint(starPath, NULL, 100.0f, 280.0f);
CGPathAddLineToPoint(starPath, NULL, 260.0f, 170.0f);
CGPathAddLineToPoint(starPath, NULL, 60.0f, 170.0f);
CGPathAddLineToPoint(starPath, NULL, 220.0f, 280.0f);
CGPathCloseSubpath(starPath);
CAKeyframeAnimation *animation = nil;
animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[animation setDuration:10.f];
[animation setDelegate:self];
[animation setPath:starPath];
CFRelease(starPath);
starPath = nil;
[[_imageView layer] addAnimation:animation forKey:@"position"];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
[_drawButton setEnabled:YES];
}
第二种,来回弹跳效果
{
[UIView beginAnimations:@"Slide Around" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(viewAnimationDone:)];
[UIView setAnimationRepeatCount:3];
[UIView setAnimationRepeatAutoreverses:YES];
CGPoint center = [[self imageView] center];
center.y += 100;
[[self imageView] setCenter:center];
[UIView commitAnimations];
}
- (void)viewAnimationDone:(NSString *)name{
[UIView beginAnimations:@"Show Button" context:nil];
[[self button] setAlpha:1.0];
[UIView commitAnimations];
}
第三种,缩放效果
@property (nonatomic) CALayer *scaleLayer;
[_scaleLayer removeAnimationForKey:@"scaleAnimation"];//删除动画效果
-
(void)initScaleLayer{
_scaleLayer = [[CALayer alloc] init];
_scaleLayer.backgroundColor = [UIColor blueColor].CGColor;
_scaleLayer.frame = CGRectMake(60, 20 + 30, 50, 50);
_scaleLayer.cornerRadius = 10;
[self.view.layer addSublayer:_scaleLayer];CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];//放大多少倍
scaleAnimation.autoreverses = YES; //旋转后再旋转到原来的位置
scaleAnimation.fillMode = kCAFillModeRemoved;
scaleAnimation.repeatCount = MAXFLOAT;
scaleAnimation.duration = 0.8;[_scaleLayer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
}
第四种,翻转效果 -
(void)initGroupLayer{
CALayer *groupLayer = [[CALayer alloc] init];
groupLayer.frame = CGRectMake(60, 340 + 100 +kYOffset, 50, 50);
groupLayer.cornerRadius = 10;
groupLayer.backgroundColor = [UIColor purpleColor].CGColor;
[self.view.layer addSublayer:groupLayer];CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];
scaleAnimation.autoreverses = YES;
scaleAnimation.repeatCount = MAXFLOAT;
scaleAnimation.duration = 0.8;CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
moveAnimation.fromValue = [NSValue valueWithCGPoint:groupLayer.position];
moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(320 - 80, groupLayer.position.y)];
moveAnimation.autoreverses = YES;
moveAnimation.repeatCount = MAXFLOAT;
moveAnimation.duration = 2;CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
rotateAnimation.fromValue = [NSNumber numberWithFloat:0.0];
rotateAnimation.toValue = [NSNumber numberWithFloat:6.0 * M_PI];
rotateAnimation.autoreverses = YES;
rotateAnimation.repeatCount = MAXFLOAT;
rotateAnimation.duration = 2;CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
groupAnimation.duration = 2;
groupAnimation.autoreverses = YES;
groupAnimation.animations = @[moveAnimation, scaleAnimation, rotateAnimation];
groupAnimation.repeatCount = MAXFLOAT;[groupLayer addAnimation:groupAnimation forKey:@"groupAnimation"];
}