0
我有一個包含圖形的NSScrollView。繪圖是NSView的一個子類,是一個放置目標。我有另一個名爲dragBox的類,它是一個NSBox和一個拖動源。我希望能夠動態更改圖形的大小,以適應拖動NSScrollView大小以外的dragBox。目前,我在NSScrollView的內容視圖中定義了一個可自動滾動的「熱點區域」。問題是,當我拖放dragBox時,它不會將它放到剛創建的虛擬空間中。它將相對於視口的大小放下它。這是代碼。如何基於拖動的控件動態滾動NSScrollView
@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以便將它放入提供的虛擬空間中?
布魯斯