Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

99miles

macrumors member
Original poster
Oct 10, 2008
50
0
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!
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.