My application is able to do some simple figure's drawing (until I get a more stable code, I am sticking with only one figure) and it's also able to re-size them. The code I use to create a UIView
is the following :
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self setContextFillColor:context];
[self setContextStrokeColor:context];
[self setLineWidth:context];
CGFloat lineThickness = [self lineWidth] ;
CGFloat halfLineThickess = lineThickness / 2.0f;
CGContextAddRect(context, CGRectMake(halfLineThickess,halfLineThickess, rect.size.width - lineThickness, rect.size.height - lineThickness));
CGContextDrawPath(context, kCGPathEOFillStroke);
}
Which gives me, with an input size of (100.0f,100.0f), this:
This figure is inside a "container" UIView
which in turn is inside an UIScrollView
. My problem with this is when I am re-sizing my figure and I reach sizes of around 1000*1000 (my "container" is 20,000*20,000), I start receiving memory warnings and the application finally gives up. So my questions are:
1) Should I consider putting a maximum size for the UIView
?
2) How could I use the instruments to track this kind of problems, and see where the problem is coming (or where is the heavy lifting being done).
3) Should I use some kind of caching like this?
4) Are there some general best practices to consider, when drawing an UIView
?
5) Should I consider CALayer
, although I need to listen to touches?
The re-sizing of the UIView
is based mostly on this.
UIView
's properties would be enough. But thanks for the suggestion. – RhianaCATiledLayer
developer.apple.com/library/ios/#documentation/GraphicsImaging/… – Resorcinol