AsyncDisplayKit 图像显示闪烁

AsyncDisplayKit Image Display Blinks

我正在尝试结合使用 facebook 的 AsyncDisplayKit 和 DMLazyScrollView。移动到 next/previous 图像时,视图会闪烁,如下所示:

没有AsyncDisplayKit,就不会出现这个问题。

这是负责获取图像的代码部分:

- (UIViewController *) controllerAtIndex:(NSInteger) index {
    if (index > viewControllerArray.count || index < 0) return nil;
    id res = [viewControllerArray objectAtIndex:index];
    if (res == [NSNull null]) {
        UIViewController *contr = [[UIViewController alloc] init];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            ASNetworkImageNode *_mediaNode = [[ASNetworkImageNode alloc] init];
            _mediaNode.backgroundColor = ASDisplayNodeDefaultPlaceholderColor();
            _mediaNode.URL = [NSURL URLWithString:[imagesUrl objectAtIndex:index]];
            _mediaNode.frame = contr.view.bounds;

            dispatch_async(dispatch_get_main_queue(), ^{
                [contr.view addSubview:_mediaNode.view];
            });
        });
        [viewControllerArray replaceObjectAtIndex:index withObject:contr];
        return contr;
    }
    return res;
}

很高兴知道是否有人解决了这个问题。

开始吧,这是闪烁原因的答案:

When converting an app to use AsyncDisplayKit, a common mistake is to add nodes directly to an existing view hierarchy. Doing this will virtually guarantee that your nodes will flash as they are rendered.

async display kit docs