Objective c 从drawAtPoint绘制的屏幕中删除字符串

Objective c 从drawAtPoint绘制的屏幕中删除字符串,objective-c,macos,cocoa,Objective C,Macos,Cocoa,我只想问一下如何从屏幕上删除NSString的-drawAtPoint方法绘制的字符串 详情如下: 绘图函数 void DrawString (NSString * str) { [str drawAtPoint: NSMakePoint(x,y) withAttributes: MyAttributes]; } 清晰功能 void EraseString (NSString * str) { //Code to delete str from th

我只想问一下如何从屏幕上删除NSString的-drawAtPoint方法绘制的字符串

详情如下:

绘图函数

  void  DrawString (NSString * str)
  {
      [str drawAtPoint: NSMakePoint(x,y) withAttributes: MyAttributes];
  }
清晰功能

 void EraseString (NSString * str)
 {
       //Code to delete str from the screen.
 }
你不会“抹掉”你画的东西。下次调用
drawRect:
时,您不需要绘制它。例如,在视图中设置字符串的状态时,调用
setNeedsDisplay:
例如:

-(void)setShowString:(BOOL)showString
{
    _showString = showString;
    [self setNeedsDisplay:YES];
}
然后在
drawRect:
方法中,检查以下状态:

if ([self showString])
    [str drawAtPoint: NSMakePoint(x,y) withAttributes: MyAttributes];
调用setShowString时,该字符串将显示或隐藏该字符串:

或者,可以设置字符串值(假定为非圆弧项目):

并检查
drawRect:
中的字符串:

if ([[self str] length] > 0)
    [_str drawAtPoint: NSMakePoint(x,y) withAttributes: MyAttributes];

在我的例子中,我维护一个要显示的字符串数组。我刚刚从字符串中删除了它们并使用了您的方法。
if ([[self str] length] > 0)
    [_str drawAtPoint: NSMakePoint(x,y) withAttributes: MyAttributes];