我自己發現了真棒解決方案。訣竅是在表格視圖數據源NSArray中創建已經有圓角的圖像。我做了這樣的方向:
1.1添加QuartzCore框架項目。
1.2然後爲UIImage添加類別。的UIImage + RoundedCorners.h:
#import <UIKit/UIKit.h>
@interface UIImage (RoundedCorners)
- (UIImage *)imageWithRoundedCorners:(CGFloat)radius;
@end
1.3的UIImage + RoundedCorners.m:
#import "UIImage+RoundedCorners.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIImage (RoundedCorners)
- (UIImage *)imageWithRoundedCorners:(CGFloat)radius;
{
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = CGRectMake(0, 0, self.size.width, self.size.height);
imageLayer.contents = (id)self.CGImage;
imageLayer.masksToBounds = YES;
imageLayer.cornerRadius = radius;
UIGraphicsBeginImageContext(self.size);
[imageLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return roundedImage;
}
@end
2.1創建的NSArray(NSMutableArray的)與圖像,你要使用:
_thumbnailImages = [[NSMutableArray alloc] initWithCapacity:[_dishes count]];
for (int counter = 0; counter < [_dishes count]; counter++)
{
EBEntityDish *dish = [_dishes objectAtIndex:counter];
[_thumbnailImages addObject:[dish.image.thumbnailImage imageWithRoundedCorners:IMAGE_CORNER_RADIUS]];
}
2.2備註:
個
IMAGE_CORNER_RADIUS == your image corner radius.
_dishes - My objects that contain images small size (144 x 144)
2.3結果:
My FPS increased on 10 - 20 FPS! Really awesome! Good luck!