我没有在互联网上找到任何解决方案,所以我决定在这里问我的问题。有一个很酷的动画效果,你可以用一个按钮来制作,如果你点击它,它会像弹出一样跳跃和降落。如果你明白我的意思。我的意思是,如果你击中地板一次,按钮会像橡皮球一样弹跳。我在许多不同的游戏应用程序上看到了这种效果,并想在我的应用程序中这样做。这实际上就像让按钮变大,如果被点击,它会立即变小。有人知道怎么做这个吗?
提前致谢。
查看此博客,该博客描述了图标上的弹跳效果。这应该会引导你走向正确的方向。还可以查看这个 lantean 博客和这个 cocoanetics 博客。
这是他正在使用的代码,
+ (CAKeyframeAnimation*)dockBounceAnimationWithViewHeight:(CGFloat)viewHeight
{
NSUInteger const kNumFactors = 22;
CGFloat const kFactorsPerSec = 30.0f;
CGFloat const kFactorsMaxValue = 128.0f;
CGFloat factors[kNumFactors] = {0, 60, 83, 100, 114, 124, 128, 128, 124, 114, 100, 83, 60, 32, 0, 0, 18, 28, 32, 28, 18, 0};
NSMutableArray* transforms = [NSMutableArray array];
for(NSUInteger i = 0; i < kNumFactors; i++)
{
CGFloat positionOffset = factors[i] / kFactorsMaxValue * viewHeight;
CATransform3D transform = CATransform3DMakeTranslation(0.0f, -positionOffset, 0.0f);
[transforms addObject:[NSValue valueWithCATransform3D:transform]];
}
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.repeatCount = 1;
animation.duration = kNumFactors * 1.0f/kFactorsPerSec;
animation.fillMode = kCAFillModeForwards;
animation.values = transforms;
animation.removedOnCompletion = YES; // final stage is equal to starting stage
animation.autoreverses = NO;
return animation;
}
- (void)bounce:(float)bounceFactor
{
CGFloat midHeight = self.frame.size.height * bounceFactor;
CAKeyframeAnimation* animation = [[self class] dockBounceAnimationWithViewHeight:midHeight];
[self.layer addAnimation:animation forKey:@"bouncing"];
}