iOS:使用可拖动对象实现drawRect时要遵循的标准规则



我的应用程序允许用户在屏幕上拖动圆圈。我想知道是否有任何标准的步骤,以实现这一点,特别是关于标记视图的正确区域为脏。我目前正在做以下操作:

//Get initial touch point and draw a circle there. Use touch point and size of circle to pass the mark the appropriate CGRect as dirty so that it gets redrawn
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//Get new touchpoint and draw a circle there. Use the union of the previous CGRect and the new one (based on the touch point and circle size) to tell drawRect: what area of the screen to redraw.
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

这看起来对吗,还是我应该做其他一些基本的工作?

假设你的视图是画圆圈的东西,那么你所做的应该是好的。只需使用[self setNeedsDisplayInRect: circleRect]将圆圈的旧位置和新位置标记为dirty

最新更新