【发布时间】:2015-08-06 13:27:18
【问题描述】:
由于调用 setNeedsDisplay 方法而面临内存警告问题。以下是我完成的过程:
考虑我的应用程序是在非常大的 UIView(比如:MyExampleView)中使用CAShapeLayer 画线,比如(10000 * 8000)。在这个视图中,我使用panGesture 方法徒手画线。所以在平移手势方法中,每次都在“MyExampleView”中调用setNeedDisplay,因此它会收到内存警告并导致应用程序崩溃。
谁有建议可以告诉我们
添加代码:
-(void)handlePan:(UIPanGestureRecognizer *)gesture
{
exampleArea.currentX = someValue1;
exampleArea.currentY = someValue2;
// this someValue1 and someValue2 value keep on changing based on hand moving;
[exampleArea setNeedsDisplay]; // Here exampleArea - MyExampleArea class is subclass of UIView.
}
@implementation MyExampleArea
{
}
-(void)drawRect:(CGRect)rect
{
CGMutablePathRef linePath = nil;
linePath = CGPathCreateMutable();
if(!lineShape)
{
lineShape = [QlineShapes layer];
}
lineShape.lineWidth = 2.0f;
lineShape.lineCap = kCALineCapRound;;
lineShape.strokeColor = [[UIColor blueColor] CGColor];
CGPathMoveToPoint(linePath, NULL,100.0f,100.0f);
CGPathAddLineToPoint(linePath, NULL, _currentX, _currentY);
// _currentX, _currentY value will change
lineShape.path = linePath;
[self.layer addSublayer:lineShape];
CGPathRelease(linePath);
}
【问题讨论】:
-
请分享你的代码
标签: ios objective-c memory warnings