1

喜用NSURL的动态高度,目前,我正忙着跟我有动态UI像Pinterest的UICollectionViewCell有对图片下载

概念 我需要像上图中的UI项目之一。为此,我已经使用了UICollectionView并试图为每个单元给出动态高度 。我无法取得任何成就,如 这样的UI。我还用了一些自定义的UICollectionView即 “PSCollectionView”,“PSTCollectionView”等。

在所有案例中,我发现一个普遍的事情有关的图像和他们的 高度。他们都从本地来源获取图像,并将 高度的图像存储在本地存储中,或直接从 获取图像,我需要从网络服务器获取图像,使用NSURL 然后我可以给每个高度细胞..但我怎么能 做到这一点?任何想法...请让我知道,如果你有任何 适当的解决方案。

参考图像如下。

enter image description here

+0

从哪里获得Web服务?我的意思是这是来自公共来源? –

+0

@Nilesh你有没有动态的细胞大小?我也想和你一样。但是我也加上了那张图片的标签。 –

回答

3

我想去这种方法对我现有的项目拥有动态图像,还有一件事你会得到最快的响应。

-(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; 
} 
0

使用UICollectionViewDelegateFlowLayout方法

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath; 
0

可能它会迟到,但谁这么以往任何时候都正在试图获得在collectionviewcontroller动态细胞高度的自定义单元格,或者如果面临问题的闪烁孩子的任何一个,请确保您使用的sizeForItemAtIndexPath方法从UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;