【发布时间】:2013-09-29 18:03:55
【问题描述】:
我正在编写一个用户可以在 uiview 上绘制的应用程序。如果该 uiview 是正常大小(比如说 1024 x 720),它会完美运行。但是,如果我将其添加到 uiscrollview 并且该尺寸为 1024 x 3000,它会变得非常慢。另外,如果高度为 10000,应用程序会当场崩溃。我想知道怎么做。
- (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++;
}
}
}
【问题讨论】:
标签: ios uiview uiscrollview drawrect large-files