CABasicAnimation issues

Discussion in 'iOS Programming' started by 99miles, Jun 6, 2009.

  1. 99miles macrumors member

    Joined:
    Oct 10, 2008
    #1
    I have a UIImageView that I'm trying to animate, but the animation puts it in the wrong location.

    As a test I got the frame of the image:

    Code:
    CGRect frame = bucketView.characterImageView.frame;
    frame.origin.y = 27;
    
    then tried setting the frame to 27 in both of the following ways:

    Code:
    bucketView.characterImageView.frame = frame;
    [bucketView.characterImageView layer].frame = frame;
    
    In each case the UIImageView is set exactly where I's expect it.

    However, when I try to animate it, is uses a different location (above where it should be), even though I'm still using a y value of 27

    Code:
    CABasicAnimation *positionAnimation;
    positionAnimation				= [CABasicAnimation animationWithKeyPath:@"position.y"];
    positionAnimation.fromValue		= [NSNumber numberWithFloat:27.0f];
    positionAnimation.toValue		= [NSNumber numberWithFloat:27.0f];
    positionAnimation.duration		= 1;
    	
    anim				= [CAAnimationGroup animation];
    anim.animations		= [NSArray arrayWithObjects: positionAnimation, nil];
    anim.duration		= 1;
    
    [[bucketView.characterImageView layer] addAnimation:anim forKey:@"position.y"];
    
    I have to same to and from values in that animation simply as a test.

    Any ideas why it's placing the image in the wrong location?

    Thanks!
     
  2. 99miles thread starter macrumors member

    Joined:
    Oct 10, 2008
    #2
    Aw, crappers. I realized in the animation position.y is not the same as the y of the frame. It's relative to the anchor point, which the docs say is (0,0) by default, but it's actually the centerpoint.

    Getting closer.
     

Share This Page