0

我想让我的动画带有弓形而不是直线。
这是我的代码:

UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-125, 100, 125, 125)];
    logoImageView.image = logoImage;
    logoImageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:logoImageView];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
logoImageView.frame = CGRectMake(screenRect.size.width - 192, 190, logoImageView.frame.size.width, logoImageView.frame.size.height);
[UIView commitAnimations];

我也试过这个,但它不起作用(它只需要最后一个中心移动)。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
logoImageView.center = CGPointMake ...
logoImageView.center = CGPointMake ...
logoImageView.center = CGPointMake ...

等等

logoImageView.frame = CGRectMake(screenRect.size.width - 192, 190, logoImageView.frame.size.width, logoImageView.frame.size.height);
[UIView commitAnimations];

我怎样才能做到这一点?

先感谢您。

4

1 回答 1

3

正如我在评论中提到的,您将需要CAKeyframeAnimation执行多个类似的值。简单的方法是只指定值并指定calculationMode它们应该如何插值。如果这不能给你想要的结果,你可以指定任何CGPath你想要的视图动画。你正在尝试做的代码看起来像这样。

CAKeyframeAnimation *curvedAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
curvedAnimation.duration = 3.0;
curvedAnimation.calculationMode = kCAAnimationCubic;
curvedAnimation.values = @[[NSValue valueWithCGPoint:currentPoint],
                           [NSValue valueWithCGPoint:firstPoint],
                           [NSValue valueWithCGPoint:secondPoint],
                           [NSValue valueWithCGPoint:endPoint]];

curvedAnimation.fillMode = kCAFillModeBackwards; // Show first value before animation begins

logoImageView.layer.position = endPoint; // Change position to end value (Core Animation only performs the animation, it won't change the property you are animating)
[logoImageView.layer addAnimation:curvedAnimation
                           forKey:@"my bow animation"];

如果你是 Core Animation 的新手。可以在QuartzCore.framework其中找到您必须添加到项目以及#import <QuartzCore/QuartzCore.h>代码中的位置。

于 2013-03-06T22:40:00.520 回答