0

This' my code in which I'm trying 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]; 
neha
  • 6,327
  • 12
  • 46
  • 78

1 Answers1

3

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.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Rob, I'm able to see my imageView located at upper left corner using this but without the animation. I'm adding this view to self after animating. – neha Jan 07 '10 at 05:46
  • I see you're edits; you're still leaking the view. That said, the first problem above is that you're animating a CGRect property (frame) with a CGSize. I'm surprised you're not receiving some kind of warning in your run log, but in any case, if you want to animate frame, you need to pass in CGRects, not CGSizes. – Rob Napier Jan 07 '10 at 14:15
  • Rob, frame is a derived property, so if you want to change anything related to it, like e.g. for changing size you have to provide valueWithCGSize like the way I have done it here or if you want to change position, you have to provide valueWithCGPoint etc. – neha Jan 08 '10 at 05:37
  • What you've done here will repeatedly call [layer setFrame:CGSizeMake(x,y)]. That's not legal. setFrame: takes a CGRect, not a CGSize. You want to animate the property bounds.size, not frame. http://developer.apple.com/iphone/library/qa/qa2008/qa1620.html – Rob Napier Jan 08 '10 at 14:56
  • Thanx Rob for your patience... It helped! – neha Jan 09 '10 at 05:50