Thing is, I have this custom view (3 of them) in my one cell, and it does a lot of clipping and rendering of images... I really need it to do this faster.
In my 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);
Now, I have 3 of these things per cell, and even with recycling, it still needs to determine which part of the image to draw and draw it...
I really can't think of a way to speed this up :( Any help is greatly appreciated!
The result of this is 2 images. One is a right triangle with its right angle at the top left, the other is a right triangle with its right angle at the bottom right.