Why is drawRect leaving parts of image?

你说的曾经没有我的故事 提交于 2019-12-06 08:17:30
HalR

You've taken over DrawRect, so its only going to do what you manually do in the dra

Fill in the entire bar area with background color before you draw anything on top of it.

You are re-using cells, so, for example, you have the Turf Hotel Restaurant graph showing underneath the 2nd version of the Grace Market/Maple Plaza.

CGContextSetFillColor(ctx, yourBackgroundColor);
CGRect fullBox = CGRectMake(xOffset, yOffset, kScoreBoxWidth * 17, kScoreBoxHeight);
CGContextAddRect(ctx, fullBox);
CGContextFillPath(ctx);

If you are just clearing the background in your cells instead of having a background color. then:

CGContextClearRect(context, rect);

at the start of your DrawRect may be more appropriate.

REVISION:

Looking at your question more closely, the root problem is that you are not finding and deleting the old DSFScoreboardView's. Perhaps you should try a recursive search through the subviews. Like:

- (void)logViewHierarchy {
    NSLog(@"%@", self);
    for (UIView *subview in self.subviews) {
        //look right here for your DSFScorebarView's
        [subview logViewHierarchy];
    }
}
@end

// In your implementation
[myView logViewHierarchy];

(taken from https://stackoverflow.com/a/2746508/793607)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!