JH9*_*H95 3 xcode cocoa objective-c uiview ios
我知道这个问题被问了很多,但我已经尝试了所有其他答案,我无法弄清楚为什么动画停止选择器不被调用.这是代码:
-(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];
Run Code Online (Sandbox Code Playgroud)
}
这是发送所有正确参数的主要动画功能.
- (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?");
}
Run Code Online (Sandbox Code Playgroud)
我的NSLog都没有显示文字.我究竟做错了什么?
你需要做什么 -
[UIView beginAnimations:annKey context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
// Now define rest.
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
image.transform = transform;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)