我正在处理拖放视图,并在网络上找到了一些拖放操作的处理程序。我想让它在用户将文件拖到拖放区域上时变为蓝色,并在退出拖放区域时再次变为灰色。问题是当您将鼠标拖到它上面或退出它时它没有更新。继承人的一些代码:
- (void)drawRect:(NSRect)rect
{
NSRect bounds = [self bounds];
[[NSColor grayColor] set];
[NSBezierPath fillRect:bounds];
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSRect bounds = [self bounds];
[[NSColor blueColor] set];
[NSBezierPath fillRect:bounds];
return NSDragOperationCopy;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender {
NSRect bounds = [self bounds];
[[NSColor grayColor] set];
[NSBezierPath fillRect:bounds];
}
谢谢你的帮助。