UIView アニメーションのように、通常のデリゲート パターンを非同期ブロックに変換したいと考えています。Apple が UIView アニメーションで行ったことをやりたい、このようなものに置き換えたい
[UIView beginAnimations:nil context:nil];
[UIview setAnimationDuration:0.25f];
[UIView setAnimationDidStopSelector:@selector(myStopSelector)];
[UIView setAnimationDelegate:self];
// Animation stuff
[UIView commitAnimations];
// In another part of my class
- (void)myStopSelector {
// Completion stuff
}
このようなもので
[UIView animateWithDuration:0.25f animations:^{
// Animation stuff
} completion:^(BOOL finished) {
// Completion stuff
}]
私の場合、非同期操作を待っている間にこの動作が必要です。現在、特定のプロトコルをリッスンして操作を完了し、結果を得るオブザーバーを追加しています。TWRequest のように、デリゲート パターンを使用して非同期完了ハンドラー ブロックを使用することは避けたい
[myTWRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
}];
どうやってやるの?
どうもありがとう。