私は自分自身に何度も質問してきました。のは、以下の例を見てみましょう:アニメーション化されたコード(completionBlock)とアニメーション化されていないコードの間のコードが重複しないようにする方法
if (animated) {
[UIView animateWithDuration:0.3 animations:^{
view.frame = newFrame;
} completion:^(BOOL finished) {
// same code as below
SEL selector = @selector(sidePanelWillStartMoving:);
if ([currentPanningVC conformsToProtocol:@protocol(CHSurroundedViewDelegate)] &&
[currentPanningVC respondsToSelector:selector]) {
[(id)self.currentPanningVC sidePanelWillStartMoving:self.currentPanningVC];
}
if ([centerVC conformsToProtocol:@protocol(CHSurroundedViewDelegate)] &&
[centerVC respondsToSelector:selector]) {
[(id)centerVC sidePanelWillStartMoving:self.currentPanningVC];
}
}];
}
else {
view.frame = newFrame;
// same code as before
SEL selector = @selector(sidePanelWillStartMoving:);
if ([currentPanningVC conformsToProtocol:@protocol(CHSurroundedViewDelegate)] &&
[currentPanningVC respondsToSelector:selector]) {
[(id)self.currentPanningVC sidePanelWillStartMoving:self.currentPanningVC];
}
if ([centerVC conformsToProtocol:@protocol(CHSurroundedViewDelegate)] &&
[centerVC respondsToSelector:selector]) {
[(id)centerVC sidePanelWillStartMoving:self.currentPanningVC];
}
}
完了ブロック内のコードおよび非アニメーションコードブロックが同じです。そして、これはよくこのようなものです。私は両方の結果が同じであることを意味しますが、1つはアニメーション化されました。
これは本当にまったく同じ2つのコードブロックを持つことを迷惑に思いますが、どうすればそれを避けることができますか?
ありがとうございます!
ええと、これは完璧です!ありがとう、たくさんの人! – florion
@flop嬉しいです! – Vignesh