我正在尝试使用样式将旧样式动画转换为块。以下代码工作正常:
[UIView beginAnimations:@"ResizeAndMove" context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationDelay:0];
[UIView setAnimationBeginsFromCurrentState:YES];
selected_view.frame = targetSlot.frame;
selected_view.center = targetSlot.center;
[UIView commitAnimations];
但是这个转换不会工作:
[UIView animateWithDuration:.3f
animations:^{
selected_view.frame = targetSlot.frame;
selected_view.center = targetSlot.center;
}
];
它说:
2012-10-17 12:32:50.256 myapp[311:207] *** +[UIView
animateWithDuration:animations:]: unrecognized selector sent to class
0x21b989c 2012-10-17 12:32:50.259 myapp[311:207] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason: '***
+[UIView animateWithDuration:animations:]: unrecognized selector sent to class 0x21b989c'
我正在使用带有 iPad 模拟器的 ios 4.1。它编译正常,但总是崩溃。想不通怎么回事。甚至来自苹果开发的简单示例:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
以相同的方式工作 - 它只是以相同的消息崩溃(仅添加“完成:”)。争论有什么问题?到底是哪个论点?我需要导入一些东西来添加对块的支持吗?但它编译得很好......我什至可以在 UIKit/UIView 中看到:
...
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0, completion = NULL
...