我正在尝试创建一个UIImageViews的NSMutableArray来提供iCarousel。每个UIImageView都有一个视频缩略图和标签名称和长度。 我发现,一旦加载了超过10个视频缩略图,在iCarousel加载时创建视频缩略图会导致无法接受的延迟。我还没有找到一种异步方式来创建iCarousel所需的视频缩略图。
我正在尝试的当前解决方案是在保存视频时将视频和匹配的缩略图保存到apps文档文件夹。然后将它们加载到2个时间排序的数组中(具有完全相同的计数)。
我正在尝试解决的难题是使用来自一个阵列的缩略图来创建新的UIImageViews数组的最佳方法是什么,以及来自视频的名称和视频长度以及第二个数组中匹配的索引。 / p>
我之前使用此代码从一组视频中创建了大拇指和标签。
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 :(得分: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];
}];