【问题标题】:Manipulating UIImageView During Animation with CAKeyframeAnimation使用 CAKeyframeAnimation 在动画期间操作 UIImageView
【发布时间】:2011-08-31 14:54:58
【问题描述】:

我需要将对象(UIImageView)从 A 点移动到 B 点,然后将 B 点的图像旋转 180 度以面向相反方向并将对象从 B 移动到 A(向后)。

我有下面的代码,它从 A 移动到 B。我也知道如何旋转 UIImageView。但是如何知道对象何时到达 B 点以及考虑到屏幕上有很多对象如何应用旋转动作?

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation    animationWithKeyPath:@"position"];
pathAnimation.duration = speed;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO; 
CGMutablePathRef pointPath = CGPathCreateMutable();
CGPathMoveToPoint(pointPath, NULL, rect.origin.x, rect.origin.y);
CGPathAddLineToPoint(pointPath, NULL, x, y);
pathAnimation.path = pointPath;
CGPathRelease(pointPath);   
[imageView.layer addAnimation:pathAnimation forKey:[NSString    stringWithFormat:@"pathAnimation%@",objId]];
[imageView release];

【问题讨论】:

    标签: iphone uiimageview cakeyframeanimation


    【解决方案1】:

    在 CAAnimation 对象上设置一个委托,并在委托中实现animationDidStop:finished: 方法。

    OTOH,您描述的动画听起来很容易通过 UIView 的动画支持完成。如果您的目标是 4.0 及更高版本,请参阅 Animating Views with Blocks,如果您仍然面向早期版本,请参阅 Animating Views

    【讨论】:

    • 我实际上有一条复杂的路要走。为简单起见,我使用 A 和 B。你提到了 CGAnimation,但我没有初始化该对象。我会研究如何去做。谢谢
    • @Vad:我指的是 CAAnimation,它是 CAKeyframeAnimation 的超类。 Apple 的类有太多不同的小前缀。
    【解决方案2】:

    您可以使用 CAAnimation 委托方法

    -(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      相关资源
      最近更新 更多