2014-02-17 82 views
0

我想创建一个UIImageViews的NSMutableArray来提供一个iCarousel。每个UIImageView都有一个视频的缩略图和名称和长度的标签。 我发现,一旦有超过10个视频缩略图加载,随着iCarousel加载创建视频缩略图会导致不可接受的延迟。我还没有找到异步的方式来创建视频缩略图,因为它们是iCarousel所需要的。创建一个UiImageVIews阵列从2个数组提供iCarousel

我正在努力工作的当前解决方案是在保存视频时将视频和匹配的缩略图保存到应用程序文档文件夹。然后将它们加载到2个时间排序的数组中(具有完全相同的计数)。

我试图解决的难题是什么是使用一个数组中的缩略图图像和第二个数组中匹配的索引的视频的名称和视频长度来创建新数组的UIImageViews的最佳方法。

我以前使用这段代码创建了一个只有视频数组的大拇指和标签。

UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 135.0f)]; 
    ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"]; 
    view.contentMode = UIViewContentModeCenter; 

    UIImage *thumb = [UIImage imageWithContentsOfFile:anyPath]; 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:view.bounds]; 
    imageView.tag = 1000; 
    [imageView setImage:thumb]; 
    [view addSubview:imageView]; 

    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150.f, 200.f, 25.f)]; 
    [nameLabel setTextAlignment:NSTextAlignmentLeft]; 
    [nameLabel setTag:2000]; 
    [nameLabel setTextColor:[UIColor whiteColor]]; 
    [nameLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12.f]]; 
    [nameLabel setText:anyPath.lastPathComponent]; 
    [view addSubview:nameLabel]; 

    UILabel *lengthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150.f, 200.f, 25.f)]; 
    [lengthLabel setTextAlignment:NSTextAlignmentRight]; 
    [lengthLabel setTag:3000]; 
    [lengthLabel setTextColor:[UIColor whiteColor]]; 
    [lengthLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12.f]]; 
    [lengthLabel setText:[MediaManager lengthOfVideoWithPath:anyPath]]; 
    [view addSubview:lengthLabel]; 

任何建议将不胜感激。

回答

0

行的解决方案是使用一个块,以从2个阵列创建的UIImageViews阵列像这样(在此快速加载转盘)

[self.aryVideos enumerateObjectsUsingBlock:^(id item, NSUInteger idx, BOOL *stop) { 

    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 135.0f)]; 
    ((UIImageView *)view).image = [UIImage imageNamed:@"page.png"]; 
    view.contentMode = UIViewContentModeCenter; 

    UIImage *thumb = [UIImage imageWithContentsOfFile:self.aryThumbs[idx]]; 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:view.bounds]; 
    imageView.tag = 1000; 
    [imageView setImage:thumb]; 
    [view addSubview:imageView]; 


    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150.f, 200.f, 25.f)]; 
    [nameLabel setTextAlignment:NSTextAlignmentLeft]; 
    [nameLabel setTag:2000]; 
    [nameLabel setTextColor:[UIColor whiteColor]]; 
    [nameLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12.f]]; 
    NSString *path = [item lastPathComponent]; 
    [nameLabel setText:path]; 
    [view addSubview:nameLabel]; 

    UILabel *lengthLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 150.f, 200.f, 25.f)]; 
    [lengthLabel setTextAlignment:NSTextAlignmentRight]; 
    [lengthLabel setTag:3000]; 
    [lengthLabel setTextColor:[UIColor whiteColor]]; 
    [lengthLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12.f]]; 
    [lengthLabel setText:[MediaManager lengthOfVideoWithPath:item]]; 
    [view addSubview:lengthLabel]; 


    [self.aryThumbViews addObject:view]; 
}];