Simple iPhone 2D Quartz Drawing Application

I am making a simple iPhone drawing program as a personal side project.

I capture a touch event in a subclass of UIView and pass the actual stuff to a separate CGLayer. After each rendering, I call [self setNeedsLayout] in the drawRect method: I draw a CGLayer into the screen context.

All this works great and is suitable for drawing rectangles. However, I just want a simple “free hand” mode, like so many other iPhone apps.

The way I thought it was to create a CGMutablePath, and simply:

CGMutablePathRef path;
- (void) touchBegan {
    path = CGMutablePathCreate ();
}
- (void) touchMoved {
    CGPathMoveToPoint (path, NULL, x, y);
    CGPathAddLineToPoint (path, NULL, x, y);

}
- (void) drawRect: (CGContextRef) context {
      CGContextBeginPath (context);
      CGContextAddPath (context, path);
      CGContextStrokePath (context);
}

However, after drawing for more than 1 second, performance degrades.

I would just draw every line in CGLayer off the screen, if not for opacity variable! A transparency of less than 100% causes the dots to remain on the screen connecting the lines. I looked at CGContextSetBlendingMode (), but alas, I can not find the answer.

Can someone point me in the right direction? Other iPhone apps can do this with very good performance.

+3
source share
2 answers

, CGStrokePath() , . , , , "" , , , .

, , CGAddLineToPoint(), , ( ). , , , . - , , .

+1

- , , , , 10 , ( ). .

, , ? , - , (, , 10 , , 200 - ).

, , , , , . .

+1

Source: https://habr.com/ru/post/1714706/


All Articles