動的な画像を含む既存のプロジェクトにこのアプローチを採用したいと思います。もう 1 つ、最速の応答が得られます。
-(void)fillSizeArray
{
for (int i=0; i<[self.arrGCCategory count]; i++)
{
NSNumber *width = [NSNumber numberWithFloat:200];
NSNumber *height = [NSNumber numberWithFloat:200];
NSString *urlString = [[self.arrGCCategory objectAtIndex:i] valueForKey:@"Photo"];
NSURL *imageFileURL = [NSURL URLWithString:urlString];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)imageFileURL, NULL);
if (imageSource) {
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache, nil];
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (__bridge CFDictionaryRef)options);
if (imageProperties) {
width = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelWidth);
height = (NSNumber *)CFDictionaryGetValue(imageProperties, kCGImagePropertyPixelHeight);
NSLog(@"Image dimensions: %@ x %@ px", width, height);
CFRelease(imageProperties);
}
}
CGSize size = CGSizeMake([width floatValue], [height floatValue]);
[self.cellHeights addObject:[NSValue valueWithCGSize:size]];
}
}
#pragma mark - CHTCollectionViewDelegateWaterfallLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize size = [[self.cellHeights objectAtIndex:indexPath.row] CGSizeValue];
return size;
}