0

我正在尝试将波形(高分辨率位图)渲染到具有不同帧的 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);
}

- 我在这里做错了什么?- CATiledLayer 只能按 X 轴缩放吗?

提前致谢!

4

0 回答 0