2014-02-17 119 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]; 
}];