【发布时间】:2011-10-03 09:49:15
【问题描述】:
我有一个似乎无法解决的难题。我有一个由自定义 UITableViewCells 填充的 UITableView,我需要将每个单元格的背景与背景图像混合(如 Photoshop 相乘)(背景图像是 UITableView 后面的 UIView 的一部分)。
我找到了几种方法来进行混合(并且确实有些作用)。我正在使用的混合功能是:
- (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。
基本上,我现在所做的就是通过获取单元格的框架并创建一个新图像,即该框架中的背景部分,将我结束的背景部分切掉。但是,为了使效果起作用,它本质上需要重新计算和更新每一帧(很像 alpha 效果)。哦,我尝试将计时器设置为 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);
谢谢!
【问题讨论】:
标签: objective-c ios uitableview uiimage core-graphics