我曾多次问我。 下面举一个例子:
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];
}
}
完成组和非配对代码组中的代码相同。 而这种情况往往一样,我指的是两者的结果相同,但只是一ated。
确实,这两位我都有两个完全相同的法典,我如何能够避免这种情况?
感谢!