我正在尝试使用不同的帧将波形(高分辨率位图)渲染到UIView中。我想缩放它并决定使用CATiledLayer以获得更好的性能。但结果我得到了我没想到的。
源位图(5000 x 80像素): 结果(?x 80像素): 曲目不一样;当我继续缩放/滚动时 - 它们不同。
代码本身:
+ (Class)layerClass {
return [CATiledLayer class];
}
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.loading = YES;
self.recording = NO;
CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
tiledLayer.levelsOfDetail = 7;
tiledLayer.levelsOfDetailBias = 3;
tiledLayer.tileSize = CGSizeMake(128.0, 128.0);
[self addSubview:activityView];+ (Class)layerClass {
return [CATiledLayer class];
}
-(void)drawRect:(CGRect)rect {
UIImage* image = [UIImage imageWithContentsOfFile:self.imagePath];
CGFloat scale = parent.frame.size.width/image.size.width;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
CGContextSaveGState(context);
CGContextScaleCTM(context, scale, 1.0);
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
CGContextRestoreGState(context);
}
- 我在这里做错了什么? -Could CATiledLayer只能通过X轴进行缩放?
提前致谢!