views:

477

answers:

3

Hi Everyone:

I am wondering how I would go about animating a UIView's to a specific CGPoint. The following is what I have so far (which doesn't work in it's current state):

#define MOVE_ANIMATION_DURATION_SECONDS 2

NSValue *pointValue = [[NSValue valueWithCGPoint:point] retain];
[UIView beginAnimations:nil context:pointValue];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
+1  A: 

After the begin, but before the commit, change the value on your UI View.

slf
+1  A: 

Try:

#define MOVE_ANIMATION_DURATION_SECONDS 2

[UIView beginAnimations:nil context:pointValue];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

CGRect frame = myUIViewObject.frame;
frame.origin = point;
myUIViewObject.frame = frame;

[UIView commitAnimations];
fbrereto
For some reason, the first time this runs, the animated view seems to go down on the y axis a little bit. However, after this it works fine. Any ideas?
PF1
I would check to see what the value of `point` is every time it is run - my guess is that `point` the first time is not what you'd expect.
fbrereto
Thanks for your reply fbrereton. I fixed the problem and it works great now!
PF1
A: 

If you're targeting 10.5 or above, you can use Core Animation via the animator proxy added to NSView. Try

[[someView animator] setFrame: someNewFrame];
Adam Wright
Does this work on the iPhone OS, too?
fbrereto
I don't know off the top of my head (not yet had a chance to develop for the iPhone). I would imagine so.
Adam Wright
The iPhone has a different view architecture than the Mac, so the animator proxy does not exist on the iPhone platform.
Brad Larson