开发者

iOS: Standard rules to follow when implementing drawRect: with draggable objects

My app allows the user to drag circles around on a screen. I'm wondering whether there are any standard steps to take in order to implement this, especially in regards to marking the correct areas of the view as dirty. I'm currently doing the following:

//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 *开发者_StackOverflow中文版)touches withEvent:(UIEvent *)event {

Does this seem right, or is there some other fundamental piece that I should be doing?


Assuming that your view is what is drawing the circles, then what you're doing should be fine. Just use [self setNeedsDisplayInRect: circleRect] to mark the previous and new positions of the circle as dirty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜