我有一个包含绘图的 NSScrollView。绘图是 NSView 的子类,是放置目标。我有另一个名为 dragBox 的类,它是一个 NSBox 和一个拖动源。我希望能够动态更改绘图的大小以适应将拖动框拖动到 NSScrollView 大小之外。目前我在自动滚动的 NSScrollView 的内容视图中定义了一个“热区”。问题是当我放下dragBox时,它并没有把它放在刚刚创建的虚拟空间中。它相对于视口的大小来降低它。这是代码。
@implementation Drawing
-(NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender // validate
{
NSLog(@"Updated");
_drawHintPoint = [sender draggedImageLocation];
if ([sender draggingLocation].x > [[self superview] bounds].size.width - 30)
{
NSRect scrollRect = NSMakeRect(0,0, [self bounds].size.width + 30, [self bounds].size.height) ;
[self setFrame:scrollRect];
_drawHintPoint = NSMakePoint([self bounds].size.width + 30, [sender draggingLocation].y);
[self scrollPoint:_drawHintPoint];
}
return NSDragOperationEvery;
}
-(BOOL) prepareForDragOperation:(id<NSDraggingInfo>)sender
{
NSLog(@"Prepared");
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
NSLog(@"Move Box");
NSPoint pt = _drawHintPoint;
pt.x = pt.x - 32;
pt.y = pt.y - 32;
[[_ico box] setFrameOrigin:pt];
return YES;
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
NSLog(@"Drag Entered");
_drawHintPoint = NSMakePoint(0, 0);
return NSDragOperationEvery;
}
如何放下 dragBox 以便将其放在提供的虚拟空间中?
布鲁斯