【发布时间】:2012-04-13 13:29:59
【问题描述】:
我有一个 UIImage 类别方法可以做到这一点:
- (UIImage *)subimageInRect:(CGRect)rect {
CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
UIImage *answer = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return answer;
}
还有另一种分类方法,它将一个短而宽的图像(如胶片)切成 N 个比例更均匀的图像(如帧),如下所示:
- (NSArray *)subimagesHorizontally:(NSInteger)count {
NSMutableArray *answer = [NSMutableArray arrayWithCapacity:count];
CGFloat width = self.size.width / count;
CGRect rect = CGRectMake(0.0, 0.0, width, self.size.height);
for (int i=0; i<count; i++) {
[answer addObject:[self subimageInRect:rect]];
rect = CGRectOffset(rect, width, 0.0);
}
return [NSArray arrayWithArray:answer];
}
这些被分配了 UIImageView 的 highlightAnimationImages 属性,其中一些包含在一个表中。 (并以标准方式处理。故事板原型单元格,使用 [cell viewWithTag:...] 在数据源中进行标记和访问)。
它运行良好,但只要表加载,泄漏就会报告泄漏。谁能帮我找出我做错了什么?
【问题讨论】:
-
忘了说这是在 ARC 中。
标签: iphone ios memory-leaks uiimageview uiimage