嗨,我已经实现了:

- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer)dragImageOffset
{
    NSImage *dragImage = [NSImage imageNamed:@"Drag-Icon.png"];
    NSInteger numberOfItems = dragRows.count;
    NSAttributedString *numbers = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%lu",numberOfItems] attributes:attributes];
    [dragImage lockFocus];
    NSRect numbersSurroundRect = NSMakeRect(dragImage.size.width - (numbers.size.width + 15) - strokeWidth - 5, strokeWidth, numbers.size.width + 15, boxHeight);
    NSBezierPath *circle = [NSBezierPath bezierPathWithRoundedRect:numbersSurroundRect xRadius:9.0 yRadius:9.0];
    [[NSColor redColor] set];
    [circle fill];
    [[NSColor whiteColor] set];
    [circle setLineWidth:strokeWidth];
    [circle stroke];
    numbersSurroundRect.origin.y += ((numbersSurroundRect.size.height - numbers.size.height) + 1.75);
    [numbers drawInRect:numbersSurroundRect];
    [dragImage unlockFocus];
    return dragImage;
}


在我的NSTableView子类中,当我在表中拖动许多行时,我得到:



然后,当我只拖动一两行时,我得到:



似乎返回了旧的行计数,然后在其上面绘制了新的计数...。

请问有人对此有何启示?是在我的项目中使用ARC的结果吗?

最佳答案

您正在直接绘制到原始图像上。您应该在复制之前制作一份副本,以便下次使用新副本。

09-25 18:00