【发布时间】:2012-07-03 16:37:50
【问题描述】:
我知道这个问题被问了很多,但我已经尝试了所有其他答案,但我无法弄清楚为什么动画停止选择器没有被调用。代码如下:
-(void) moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve x:(CGFloat)x y:(CGFloat)y annKey:(NSString *) annKey{
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
[UIView beginAnimations:annKey context:NULL];
[UIView commitAnimations];
}
这是发送所有正确参数的主要动画函数。
- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context
{
if ([animationID isEqualToString:@"Burn"])
{
NSLog(@"Animation: %@ has finished.",animationID);
}
NSLog(@"This does not get called, why not?");
}
我的 NSLog 都没有显示文本。我做错了什么?
【问题讨论】:
-
为什么有两个
beginAnimations? -
对不起,这是一个错误,我已经从代码中删除了第一个。但问题依然存在。
-
将这一行
[UIView beginAnimations:annKey context:NULL];移动到moveImage:duration:curve:x:y:annKey:方法的顶部。 -
只是想知道,您不使用基于块的 UIView 动画调用是否有原因?
标签: objective-c ios xcode cocoa uiview