0

问题是,我的一个单元格中有这个自定义视图(其中 3 个),它对图像进行了很多剪辑和渲染……我真的需要它来更快地完成这项工作。

在我的drawRect中:

[super drawRect:rect];

CGContextRef contextRef = UIGraphicsGetCurrentContext();

CGFloat spacer = 1.5;
if(_type == DPClippedImageViewTypeTopLeft){
    CGContextMoveToPoint(contextRef, rect.origin.x, rect.origin.y); //top left
    CGContextAddLineToPoint(contextRef, rect.origin.x, rect.origin.y);  //top left
    CGContextAddLineToPoint(contextRef, rect.origin.x + (rect.size.width) - spacer, rect.origin.y); //top right
    CGContextAddLineToPoint(contextRef, rect.origin.x, rect.origin.y + (rect.size.height) - spacer); //bottom left
    CGContextAddLineToPoint(contextRef, rect.origin.x, rect.origin.y); //top left
}
else if(_type == DPClippedImageViewTypeBottomRight){
    CGContextMoveToPoint(contextRef, rect.origin.x + (rect.size.width), rect.origin.y + spacer); //top right
    CGContextAddLineToPoint(contextRef, rect.origin.x + (rect.size.width), rect.origin.y + spacer); //top right
    CGContextAddLineToPoint(contextRef, rect.origin.x + (rect.size.width), rect.origin.y + (rect.size.height)); //bottom right
    CGContextAddLineToPoint(contextRef, rect.origin.x + spacer, rect.origin.y + (rect.size.height)); //bottom left
    CGContextAddLineToPoint(contextRef, rect.origin.x + (rect.size.width), rect.origin.y + spacer); //top right
}
else{
    CGContextMoveToPoint(contextRef, rect.origin.x, rect.origin.y);
    CGContextAddLineToPoint(contextRef, rect.origin.x, rect.origin.y);
    CGContextAddLineToPoint(contextRef, rect.origin.x, rect.origin.y + (rect.size.height));
    CGContextAddLineToPoint(contextRef, rect.origin.x + (rect.size.width), rect.origin.y + (rect.size.height));
    CGContextAddLineToPoint(contextRef, rect.origin.x + (rect.size.width), rect.origin.y);
    CGContextAddLineToPoint(contextRef, rect.origin.x, rect.origin.y);
}

// clip context to current path
CGContextClip(contextRef);

CGContextSaveGState(contextRef);

if(_type == DPClippedImageViewTypeTopLeft){
    CGContextTranslateCTM(contextRef, -rect.size.width*2.0/3.0, -rect.size.height*3.0/5.0);
}
else if (_type == DPClippedImageViewTypeBottomRight){
    CGContextTranslateCTM(contextRef, -rect.size.width*1.0/3.0, -rect.size.height*2.0/5.0);
}

CGFloat scale = (_type != DPClippedImageViewTypeNone) ? 2.0 : 1.0;
CGContextScaleCTM(contextRef, scale, scale);

// draw image
[_image drawInRect:rect];

CGContextRestoreGState(contextRef);

现在,我每个单元格有3个这样的东西,即使有回收,它仍然需要确定要绘制图像的哪个部分并绘制它......

我真的想不出一种方法来加快速度:(非常感谢任何帮助!

结果是 2 张图像。一个是直角三角形,其直角位于左上角,另一个是直角三角形,其直角位于右下角。

4

0 回答 0