0
这'我的代码,我试图改变我的imageView的大小。如果你能指出任何错误,我会非常感激..为什么我的CAKeyframeAnimation没有得到执行?
UIImageView *imageViewForAnimation = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ravan.jpg"]];
imageViewForAnimation.alpha = 1.0f;
CGSize size1=CGSizeMake(60,60);
CGSize size2=CGSizeMake(40,40);
CGSize size3=CGSizeMake(20,20);
CAKeyframeAnimation *customFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
NSArray *sizeValues = [NSArray arrayWithObjects:[NSValue valueWithCGSize:size1], [NSValue valueWithCGSize:size2], [NSValue valueWithCGSize:size3], nil];
[customFrameAnimation setValues:sizeValues];
customFrameAnimation.duration=10.0;
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], [NSNumber numberWithFloat:1.0f], nil];
[customFrameAnimation setKeyTimes:times];
customFrameAnimation.fillMode = kCAFillModeForwards;
customFrameAnimation.removedOnCompletion = NO;
[imageViewForAnimation.layer addAnimation:customFrameAnimation forKey:@"customFrameAnimation"];
[self.view addSubview:imageViewForAnimation];
Rob,我可以看到我的imageView位于左上角,但没有使用动画。动画之后,我将这个视图添加到自己。 – neha 2010-01-07 05:46:33
我看你是编辑;你仍然在泄漏视图。这就是说,上面的第一个问题是,你正在用CGSize动画CGRect属性(框架)。我很惊讶你在运行日志中没有收到某种警告,但无论如何,如果你想为框架设置动画,你需要传递CGRects而不是CGSizes。 – 2010-01-07 14:15:56
Rob,frame是一个派生属性,所以如果你想改变与它相关的任何东西,比如说。为了改变大小,你必须提供valueWithCGSize,就像我在这里完成的方式,或者如果你想改变位置,你必须提供valueWithCGPoint等。 – neha 2010-01-08 05:37:10