Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView Drawing Best Practices
    primarykey
    data
    text
    <p>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 <code>UIView</code> is the following :</p> <pre><code>- (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); } </code></pre> <p>Which gives me, with an input size of (100.0f,100.0f), this:</p> <p><img src="https://i.stack.imgur.com/OELnh.png" alt="enter image description here"></p> <p>This figure is inside a "container" <code>UIView</code> which in turn is inside an <code>UIScrollView</code>. 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:</p> <p>1) Should I consider putting a maximum size for the <code>UIView</code>?</p> <p>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).</p> <p>3) Should I use some kind of caching like <a href="https://stackoverflow.com/questions/1798414/drawing-incrementally-in-a-uiview-iphone">this</a>?</p> <p>4) Are there some general <strong>best practices</strong> to consider, when drawing an <code>UIView</code>?</p> <p>5) Should I consider <code>CALayer</code>, although I need to listen to touches? </p> <p>The re-sizing of the <code>UIView</code> is based mostly on <a href="https://github.com/spoletto/SPUserResizableView" rel="nofollow noreferrer">this</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload