0

我有一个 ASNetworkImageNode,它位于一个 constrainedSize 为 (320, 320) 的集合视图中,但在测量日志后显示 image.calculatedSize 为 (375, 375)。我在这里做错了吗?

#pragma mark - ASCellNode Delegate

- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
    CGSize availableSize = CGSizeMake(constrainedSize.height, constrainedSize.height);
    CGSize imageSize = [image measure:availableSize];

    NSLog(@"constrainedSize width: %lf and height: %lf", availableSize.width, availableSize.height);

    NSLog(@"measured image size width: %lf and height: %lf", imageSize.width, imageSize.height);

    return imageSize;
}

- (void)layout
{
    CGSize imageSize = image.calculatedSize;
    image.frame = CGRectMake(0, 0, imageSize.width, imageSize.height);
}
4

1 回答 1

0

默认情况下,ASImageNodes 将返回它们正在加载的图像的大小,您需要将图像的框架设置为所需的大小,而不是:

image.frame = CGRectMake(0, 0, imageSize.width, imageSize.height);

利用

image.frame = CGRectMake(0, 0, bounds.width, bounds.height)

或者确保您正在下载的图像是您正在寻找的确切尺寸。

于 2015-08-12T22:19:14.060 回答