我正在從一個項目中,我從UIWebView
渲染Images
,然後顯示爲tableView
與自定義UITableViewCell
。當UITableView
第一次呈現......沒有渲染圖像顯示時,所以我在單元格中顯示默認圖像(即icon-thumb.png)。一旦圖像呈現我正在重新加載UITableView
。 我這樣做如下...UIImage替換另一個UIImage不光滑
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *reuseIdentifier = @"CustomTableViewID"; CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil)
{
cell = (CustomTableViewCell *)[[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:nil options:nil] objectAtIndex:0];
}
CGRect mainImageViewFrame = CGRectMake(9, 31, 202, 171);
cell.mainImageView.frame = mainImageViewFrame;
[cell setBackgroundColor:[UIColor clearColor]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.transform = CGAffineTransformMakeRotation(M_PI * 0.5);
cell.slideNumberLbl.textColor = [UIColor whiteColor];
cell.slideNumberLbl.backgroundColor = [UIColor grayColor];
cell.slideNumberLbl.layer.cornerRadius = 5.0;
cell.slideNumberLbl.alpha = 0.5;
[cell.slideNumberLbl setTextAlignment:NSTextAlignmentCenter];
cell.slideNumberLbl.text = [NSString stringWithFormat:@"%d",indexPath.row+1];
[cell.mainImageView setBackgroundColor:[UIColor clearColor]];
[cell.reflectionImageView setContentMode:UIViewContentModeScaleToFill];
cell.reflectionImageView.alpha = 0.15;
NSFileManager *manager = [NSFileManager defaultManager];
NSString *thumbImagepath = [self.storageDirPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d_thumb%@",indexPath.row, Image_Extension_JPG]];
if([manager fileExistsAtPath:thumbImagepath]){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
__block UIImage *img = [UIImage imageWithContentsOfFile:thumbImagepath];
dispatch_async(dispatch_get_main_queue(), ^{
CGRect mainImageViewFrame = CGRectMake(9, 31, 202, 171);
cell.mainImageView.frame = mainImageViewFrame;
cell.mainImageView.image = img;
[cell.mainImageView setContentMode:UIViewContentModeScaleAspectFit];
img = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
__block UIImage *reflectionImg = [self reflectedImage:cell.mainImageView withHeight:cell.mainImageView.frame.size.height];
dispatch_async(dispatch_get_main_queue(), ^{
cell.reflectionImageView.image = reflectionImg;
reflectionImg = nil;
});
});
});
});
}
else{
CGRect mainImageViewFrame = CGRectMake(9, 31, 202, 171);
mainImageViewFrame.origin.y = mainImageViewFrame.origin.y+10;
mainImageViewFrame.size.height = mainImageViewFrame.size.height-20;
cell.mainImageView.frame = mainImageViewFrame;
[cell.mainImageView setContentMode:UIViewContentModeCenter];
[cell.mainImageView setBackgroundColor:[UIColor whiteColor]];
cell.mainImageView.image = [UIImage imageNamed:@"icon-thumb.png"];
[cell.reflectionImageView setBackgroundColor:[UIColor whiteColor]];
[cell.reflectionImageView setImage:[UIImage imageNamed:@"reflection_temp.png"]];
}
return cell;
}
的問題是,當默認圖像(即圖標thumb.png)獲取與真實圖像替換一次真實圖像渲染done..the更換不流暢,圖像替換爲閃光燈或突然全部但它需要非常光滑 ...任何建議,在此先感謝。
http://stackoverflow.com/questions/7638831/fade-dissolve-when-changing-uiimageviews-image/38350024#38350024 –