iOS Blocks - defining UIView animation-like blocks
cocoa, cocoa-touch, ios, objective-c, objective-c-blocks
Solution
You can have a method declaration such as:
- (void) performAnimationWithCompletion:(void (^)(BOOL finished))completion {
[UIView animateWithDuration:0.5 animations:^{
// your own animation code
// ...
} completion:^(BOOL finished) {
// your own completion code
// if completion block defined, call it
if(completion){
completion(YES);
}
}];
}
Then, you can call it with:
[instance performAnimationWithCompletion:^(BOOL complete){
// define block code to be executed on completion
}];
Problem
I'm trying to create a custom block like the `UIView` animation blocks. Basically I want to be able to pass either a method or any number of instructions and also provide a completion handler. My question is how would I specify the arguments part of the block definition?