开发者

Why does my CAKeyframeAnimation not get executed?

This' my code in which I'm t开发者_运维百科rying to change the size of my imageView. If you can point out any error, I'll be really grateful..

    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]; 


You're creating a UIImageView, attaching an animation to it, and then leaking it. You never attach it to a visible view. You should never even see this imageview on screen, let alone animate it.

If you want to animate an existing view, you need to attach the animation to that one, not create a new view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜