一个图标拖动的小程序,拖动图片后界面上会留有图片划过的残影,不知道如何解决,请各位大侠指教
- (void)drawRect:(CGRect)rect { [imageBox drawInRect:CGRectMake(currentX, 329, imageBox.size.width, imageBox.size.height)]; } -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *t = [touches anyObject]; CGPoint where = [t locationInView:self]; CGRect rcBox = CGRectMake(currentX, 329, imageBox.size.width, imageBox.size.height); if(CGRectContainsPoint(rcBox, where)) { touchBox = YES; currentX = where.x; [self setNeedsDisplay]; } } -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(touchBox) { UITouch *t = [touches anyObject]; CGPoint where = [t locationInView:self]; currentX = where.x; [self setNeedsDisplay]; } } -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { touchBox = NO; [self setNeedsDisplay]; }
是在模拟器上吗?换到设备上试试。
都有的 , 不知道重绘图片的时候,背景是否还需要重绘才能清除残影?
问题应该出在
imageBox drawInRect
里面,就如你所猜,应该时背景没有重绘的原因。