我正在寫一個應用程序,用戶可以在uiview上繪製。如果uiview的尺寸正常(比如說1024 x 720),它會很完美。但是,如果我將其添加到uiscrollview並且該維度爲1024 x 3000,則它變得非常緩慢。而且,如果高度爲10000,則應用程序會當場崩潰。我想知道該怎麼做。非常大的uiview和內存中的drawrect是不夠的
- (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++;
}
}
}
是。這是我的結果。 http://i40.tinypic.com/sbkidc.png。如果可能的話,你可以檢查一下這個代碼嗎? http://www.mediafire.com/download/i8jxi71it8p87tu/smoothline.zip。我在uiwebview的scrollview上使用這個uiview。我不確定是什麼導致應用程序變慢和崩潰。 –
這是我在uiwebview scrollview中繪製的完整源代碼。我收到內存警告。 http://www.mediafire.com/?jg7d6a5q2dsai4s –
@KhantThuLinn我們應該把這個聊天:http://chat.stackoverflow.com/rooms/38356/drawrect-in-very-large-uiview-and-memory-是不夠的 – Rob