动画UIView到CGPoint

时间:2009-08-26 18:17:32

标签: iphone cocoa-touch animation uiview

我想知道如何将UIView设置为特定CGPoint的动画。以下是我到目前为止(它在当前状态下不起作用):

#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];

3 个答案:

答案 0 :(得分:1)

在开始之后,但在提交之前,更改UI视图上的值。

答案 1 :(得分:1)

尝试:

#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];

答案 2 :(得分:0)

如果您的目标是10.5或更高版本,则可以通过添加到NSView的动画代理使用Core Animation。尝试

[[someView animator] setFrame: someNewFrame];