动画震动效果,,,嘿嘿。

static int numberOfShakes = 10000;//震动次数
static float durationOfShake = 1000.5f;//震动时间
static float vigourOfShake = 0.102f;//震动幅度

- (CAKeyframeAnimation *)shakeAnimation:(CGRect)frame
{
    CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
	
    CGMutablePathRef shakePath = CGPathCreateMutable();
    CGPathMoveToPoint(shakePath, NULL, CGRectGetMidX(frame), CGRectGetMidY(frame) );
	for (int index = 0; index < numberOfShakes; ++index)
	{
		CGPathAddLineToPoint(shakePath, NULL, CGRectGetMidX(frame) - frame.size.width * vigourOfShake,CGRectGetMidY(frame));
		CGPathAddLineToPoint(shakePath, NULL,  CGRectGetMidX(frame) + frame.size.width * vigourOfShake,CGRectGetMidY(frame));
	}
    CGPathCloseSubpath(shakePath);
    shakeAnimation.path = shakePath;
    shakeAnimation.duration = durationOfShake;
    CFRelease(shakePath);
    
    return shakeAnimation;
}
 
 
CAKeyframeAnimation *animation=[CAKeyframeAnimation shakeAnimation:self.loginView.layer.frame];    
    [self.loginView.layer addAnimation:animation forKey:kCATransition]; 


你可能感兴趣的:(动画震动效果,,,嘿嘿。)