小编flo*_*ion的帖子

如何避免动画(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];
    }
} …
Run Code Online (Sandbox Code Playgroud)

cocoa animation objective-c duplicates ios

0
推荐指数
1
解决办法
120
查看次数

标签 统计

animation ×1

cocoa ×1

duplicates ×1

ios ×1

objective-c ×1