【问题标题】:iOS: Standard rules to follow when implementing drawRect: with draggable objectsiOS:实现 drawRect 时要遵循的标准规则:使用可拖动对象
【发布时间】:2011-07-23 11:31:48
【问题描述】:

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

//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 {

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

【问题讨论】:

  • 您是否打算添加更多代码?或者你只是说你实现了这些方法?
  • 我不打算添加更多代码,因为我不担心实现的细节,只担心应该采取的更广泛的概念步骤。

标签: ios cocoa-touch drawing touch drawrect


【解决方案1】:

假设您的视图是绘制圆圈的内容,那么您正在做的事情应该没问题。只需使用[self setNeedsDisplayInRect: circleRect] 将圆圈的先前位置和新位置标记为脏。

【讨论】:

  • 当然。只是在寻找对先前步骤的确认。谢谢。
猜你喜欢
  • 2011-08-14
  • 1970-01-01
  • 1970-01-01
  • 2015-05-05
  • 2011-06-02
  • 1970-01-01
  • 2013-06-10
  • 2011-12-24
  • 1970-01-01
相关资源
最近更新 更多