I am writing an app that user can draw on uiview. It works perfect if that uiview is in normal size (let say 1024 x 720). However, if I add that into uiscrollview and that dimension is 1024 x 3000, it become very slow. Also, if the height is 10000, the app crash on the spot. I would like to know how to do.
- (void) drawRect: (CGRect) rect
{
NSLog(@"drawrect here 1");
if (self.arrayStrokes)
{
int arraynum = 0;
// each iteration draw a stroke
// line segments within a single stroke (path) has the same color and line width
for (NSDictionary *dictStroke in self.arrayStrokes)
{
NSArray *arrayPointsInstroke = [dictStroke objectForKey:@"points"];
UIColor *color = [dictStroke objectForKey:@"color"];
float size = [[dictStroke objectForKey:@"size"] floatValue];
[color set]; // equivalent to both setFill and setStroke
// // won't draw a line which is too short
// if (arrayPointsInstroke.count < 3) {
// arraynum++;
// continue; // if continue is executed, the program jumps to the next dictStroke
// }
// draw the stroke, line by line, with rounded joints
UIBezierPath* pathLines = [UIBezierPath bezierPath];
CGPoint pointStart = CGPointFromString([arrayPointsInstroke objectAtIndex:0]);
[pathLines moveToPoint:pointStart];
for (int i = 0; i < (arrayPointsInstroke.count - 1); i++)
{
CGPoint pointNext = CGPointFromString([arrayPointsInstroke objectAtIndex:i+1]);
[pathLines addLineToPoint:pointNext];
}
pathLines.lineWidth = size;
pathLines.lineJoinStyle = kCGLineJoinRound;
pathLines.lineCapStyle = kCGLineCapRound;
[pathLines stroke];
arraynum++;
}
}
}