代码之家  ›  专栏  ›  技术社区  ›  Brian

CAKeyframeAnimation-示例

  •  4
  • Brian  · 技术社区  · 16 年前

    我有一个菜单,它是一个可以在屏幕上滑动到指定点的日历。我想要的效果是菜单会稍微超过点,然后在点之前一点,然后降落在点上。我可以通过应用转换来移动菜单,但我希望能使这种反弹效果起作用。我在研究cakeyframeanimation,但是我找不到一个例子/教程。我看过CA编程指南,但没有找到任何东西。任何链接或帮助都是很好的。谢谢。

    1 回复  |  直到 15 年前
        1
  •  5
  •   Nathan Eror    15 年前

    我发布 some code 不久前,这正是你想要的。基本上,您需要生成自己的 CGPathRef 包含希望层命中的所有点,并使用该路径 path 的属性 CAKeyframeAnimation . 代码将如下所示:

    CGPoint path[3] = {
        FTAnimationOutOfViewCenterPoint(enclosingView.bounds, view.frame, view.center, direction),
        [self overshootPointFor:view.center withDirection:direction threshold:(overshootThreshold_ * 1.15)],
        view.center
    };
    
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    CGMutablePathRef thePath = CGPathCreateMutable();
    CGPathAddLines(thePath, NULL, path, 3);
    animation.path = thePath;
    CGPathRelease(thePath);
    

    整个方法是 here .

    推荐文章