我想制作一个弹性的弹出动画(在iPhone Google Maps应用中,有点像弹出窗口)
是否有人对制作弹性动画的数学公式有所了解?我尝试过,但没想到配方或如何做到这一点。
我想到的是:(控件或其他控件)开始增长,更快,越来越快,当达到合适的大小时,它会停止增长,但会弹性地摆动,然后停止。
任何想法,建议都不一定要那样。非常感谢!
最佳答案
尽管我尚未完全复制它,但您正在看到的是一个弹出式动画。我使用CAKeyframeAnimation对此最接近的是:
CAKeyframeAnimation *boundsOvershootAnimation = [CAKeyframeAnimation animationWithKeyPath:@"bounds.size"];
CGSize startingSize = CGSizeZero;
CGSize overshootSize = CGSizeMake(targetSize.width * (1.0f + POPINOVERSHOOTPERCENTAGE), targetSize.height * (1.0f + POPINOVERSHOOTPERCENTAGE));
CGSize undershootSize = CGSizeMake(targetSize.width * (1.0f - POPINOVERSHOOTPERCENTAGE), targetSize.height * (1.0f - POPINOVERSHOOTPERCENTAGE));
NSArray *boundsValues = [NSArray arrayWithObjects:[NSValue valueWithCGSize:startingSize],
[NSValue valueWithCGSize:overshootSize],
[NSValue valueWithCGSize:undershootSize],
[NSValue valueWithCGSize:targetSize], nil];
[boundsOvershootAnimation setValues:boundsValues];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:0.5f],
[NSNumber numberWithFloat:0.9f],
[NSNumber numberWithFloat:1.0f], nil];
[boundsOvershootAnimation setKeyTimes:times];
NSArray *timingFunctions = [NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
nil];
[boundsOvershootAnimation setTimingFunctions:timingFunctions];
boundsOvershootAnimation.fillMode = kCAFillModeForwards;
boundsOvershootAnimation.removedOnCompletion = NO;
[layer addAnimation:boundsOvershootAnimation forKey:@"boundsOvershoot"];
其中
POPINOVERSHOOTPERCENTAGE
约为0.1。这将放大一个图层(可以是UIView的后备图层),将过冲百分比,将过冲和下冲一点,然后最终变为最终大小。
它与Google地图注释的功能很接近,但并不完全相同。我认为可能需要一些时间上的细微调整。