1
我正在尝试使用2009年的一本书学习动画,并且我的理解是iOS4中动画的首选方法是使用块。我正在阅读的这本书使用了旧方法,并且我一直试图将它转化为新方法,并取得最小的成功。将旧的动画代码转换为新的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;
}];
每次我运行它(使用块的方法)获得“程序接收到的信号: “SIGABRT”和控制台显示
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+
[UIView animateWithDuration:options:animations:completion:]: unrecognized selector sent to class 0x8393b4'
我添加了lastAnimationZero的一部分,它所做的一切实际上是将lastAnimation设置为零,这样就意味着它就是这样。我也有动画,只是不想占用空间。现在不幸的是,即使在我清理了我的块语法(清理完成部分)之后,它仍然给了我同样的错误。我只是不明白。我需要做什么特殊的事情来启用块语法吗?导入一个头文件和框架? – JustAnotherCoder
无需包含头文件或框架,块语法与ios4一起提供。尝试阅读关于块的[doc](http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html)。正如我所说的,发生异常是因为'UIView'中没有定义这样的方法。 – 2011-07-08 05:41:31
啊我傻了。出于某种原因,我认为我可以排除以下任何一个块,所以我跳过了延迟,因为我不需要它。我只是把延迟:0.0,它像一个魅力。非常感谢。 – JustAnotherCoder