我正在尝试学习2009年的一本书中的动画,据我所知,在iOS4中动画的首选方法是使用块。我正在读的这本书使用的是旧方法,我一直在尝试将其转换为新方法,但收效甚微。
书中所说的:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationTimer];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(lastAnimationZero)];
//animations
[UIView commitAnimations];我的(显然是失败的)翻译:
[UIView animateWithDuration:animationTimer
options: (UIViewAnimationOptionAllowUserInteraction |
UIViewAnimationOptionCurveEaseOut)
animations: ^
{
animation
}
completion:^(BOOL finished)
{
lastAnimation = 0;
}];每次我运行它时,我(使用block方法)得到"Program received signal:"SIGABRT“,控制台显示
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+
[UIView animateWithDuration:options:animations:completion:]: unrecognized selector sent to class 0x8393b4'发布于 2011-07-08 04:31:26
检查文档中是否有UIVIew。没有这样的方法。你编写代码块语法的方式还可以,只要发送正确的消息即可。
另外,用你需要的指令替换‘lastAnimation = 0;’,这本书不会告诉你,以及旧版本中的[UIView setAnimationDidStopSelector: @selector(lastAnimationZero)];,实际上是动画停止时发送的消息,不应该直接翻译成lastAnimation = 0;。
下面是您可能想要使用的方法文档的link。
+(void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion;https://stackoverflow.com/questions/6616721
复制相似问题