PDA

View Full Version : CABasicAnimation issues




99miles
Jun 6, 2009, 11:07 AM
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:


CGRect frame = bucketView.characterImageView.frame;
frame.origin.y = 27;


then tried setting the frame to 27 in both of the following ways:


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


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!



99miles
Jun 8, 2009, 10:29 PM
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.