-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[touches anyObject];
currentPoint=[touch locationInView:self.view];
rootLayer = [CALayer layer];
rootLayer.frame = self.view.bounds;
[self.view.layer addSublayer:rootLayer];
starPath = CGPathCreateMutable();
CGPathMoveToPoint(starPath, NULL, currentPoint.x, currentPoint.y + 15.0);
for(int i = 1; i < 5; ++i)
{
CGFloat x = 15.0 * sinf(i * 4.0 * M_PI / 5.0);
CGFloat y = 15.0 * cosf(i * 4.0 * M_PI / 5.0);
CGPathAddLineToPoint(starPath, NULL, currentPoint.x + x, currentPoint.y + y);
}
CGPathCloseSubpath(starPath);
shapeLayer = [CAShapeLayer layer];
shapeLayer.path = starPath;
UIColor *fillColor = [UIColor colorWithWhite:0.9 alpha:1.0];
shapeLayer.fillColor = fillColor.CGColor;
[rootLayer addSublayer:shapeLayer];
}
- (void)dealloc {
[imageView release];
CGPathRelease(starPath);
[super dealloc];
}
当我运行性能工具泄漏时,它会占用更多内存
当我移动的时候......该怎么做....
我需要在图层上触摸电影时绘制这个星形,以便我可以在以后执行动画....
答案 0 :(得分:0)
您在dealloc中释放路径,但在touchesMoved:
内多次创建它(可能)。您可以在touchesMoved:
结束时安全地发布此资源,请考虑这样做。
此外,在您进行了更改之后,您可以从dealloc中删除该版本,因为您将永远不必在那里发布它。您的路径不存在于您的方法之外。