iphone - 弹跳按钮

标签 iphone ios uibutton

<分区>

我没有在互联网上找到任何解决方案,所以我决定在这里问我的问题。有一个很酷的动画效果,你可以用一个按钮来制作,如果你点击它,它就会像流行音乐一样跳跃和着陆。如果你明白我的意思。我的意思是,如果您一次碰到地板,按钮就会像橡皮球一样反弹。我在许多不同的游戏应用程序上看到了这种效果,并且想在我的应用程序中这样做。这实际上就像让按钮变大,然后在点击时立即变小。有人知道怎么做这个吗?

提前致谢。

最佳答案

检查 this blog描述了图标的弹跳效果。那应该引导你走向正确的方向。还有 check this lantean blogthis cocoanetics blog.

这是他使用的代码,

+ (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"];
}

关于iphone - 弹跳按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13826233/

相关文章:

iphone - 配对dispatch_resume和dispatch_suspend以强制终止应用程序

iphone - 界面方向旋转

ios - 如何从 UIScrollView 获取 UIButton 位置

iphone - 将鼠标悬停在 iPhone 上 UIButton 的状态上

iphone - 从 UIViewController 子类化时如何访问 UITableViewController 属性?

iphone - 使用核心图像进行对象检测

ios - 在列表中找到 X 和 Y 的 4 个最接近的位置

ios - didSelectRowAtIndexPath 没有推送新 View

ios - Sprite-Kit:留在使用 Tile Editor 创建的边框内

ios - 使用 UIButton 传递多个标签