I am trying to learn animation with a 2009 book and to my understanding the preferred method for animating in iOS4 is using blocks. The book I am reading uses the old method and I've been trying to translate it to the new method with minimal success.
What the book says:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationTimer];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDidStopSelector:@selector(lastAnimationZero)];
//animations
[UIView commitAnimations];
My (apparently fail) translation:
[UIView animateWithDuration:animationTimer
options: (UIViewAnimationOptionAllowUserInteraction |
UIViewAnimationOptionCurveEaseOut)
animations: ^
{
animation
}
completion:^(BOOL finished)
{
lastAnimation = 0;
}];
Everytime I run it I (using the block method) get "Program received signal: "SIGABRT" and the console shows
Terminating app due to 开发者_如何学JAVAuncaught exception 'NSInvalidArgumentException', reason: '+
[UIView animateWithDuration:options:animations:completion:]: unrecognized selector sent to class 0x8393b4'
Check the doc for UIVIew. There is no such method. The way you wrote block syntax is ok, just send the right message.
Also, replace 'animation' with the instructions you need, the book won't tell you that, as well as [UIView setAnimationDidStopSelector:
@selector(lastAnimationZero)];
in the old version, is actually the message sended when the animation stops, and shouldn't be directly translated to lastAnimation = 0;
.
Here is a link to the method documentation you probably wanted to use.
+(void)animateWithDuration:(NSTimeInterval)duration
delay:(NSTimeInterval)delay
options:(UIViewAnimationOptions)options
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion;
精彩评论