我有一个难以解决的困境。我有一个由自定义UITableViewCells填充的UITableView,我需要将每个单元的背景与背景图像(背景图像是UITableView背后的UIView的一部分)混合在一起(如Photoshop乘法)。将UITableViewCell与背景混合
我发现了几种方法来完成混合(它确实有点作用)。我使用的混合功能是:
- (UIImage *)blendOverlay:(UIImage *)topImage withBaseImage:(UIImage *)baseImage toSize:(CGFloat)imageSize
{
UIGraphicsBeginImageContext(CGSizeMake(imageSize, imageSize));
[baseImage drawInRect:CGRectMake(0.0, 0.0, imageSize, imageSize)];
[topImage drawInRect:CGRectMake(0.0, 0.0, imageSize, imageSize) blendMode:kCGBlendModeMulitply alpha:0.5];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
这是从http://www.cocoabuilder.com/archive/cocoa/280142-uiimageview-display-as-multiply.html。
基本上我现在所做的就是通过获取单元格的框架并创建一个新的图像(这是该框架中的背景部分)来切掉背景片段。但是,为了使效果起作用,它基本上需要重新计算和更新每一帧(非常像阿尔法效果)。哦,我试过只设置一个计时器,以1/60秒,并呼吁
[tableView reloadData];
但是,这只是放缓都记录下来并重绘从来没有实际发生。任何帮助非常感谢,我已经搜索了近3个小时,以利用。
哦,和对子孙后代的目的,我砍的背景图像像这样:
CGRect r = [tableView rectForRowAtIndexPath:indexPath];
CGRect r2 = [tableView convertRect:r toView:self.view];
CGImageRef imageRef = CGImageCreateWithImageInRect([m_background.image CGImage], r2);
// Get the image by calling [UIImage imageWithCGImage:imageRef]
CGImageRelease(imageRef);
谢谢!