UIView
アニメーションブロックのようなカスタムブロックを作成しようとしています。基本的に、メソッドまたは任意の数の命令を渡し、完了ハンドラーを提供できるようにしたいです。私の質問は、ブロック定義の引数部分をどのように指定するのですか?
3204 次
2 に答える
4
次のようなメソッド宣言を行うことができます。
- (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);
}
}];
}
次に、次のように呼び出すことができます。
[instance performAnimationWithCompletion:^(BOOL complete){
// define block code to be executed on completion
}];
于 2012-11-26T01:37:01.530 に答える
2
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
// other animations here
}
completion:^(BOOL finished){
// ... completion stuff
}
];
于 2012-11-26T00:46:55.457 に答える