0

Drawing を含む NSScrollView があります。Drawing は NSView のサブクラスであり、ドロップ ターゲットです。NSBox とドラッグ ソースである dragBox という別のクラスがあります。NSScrollView のサイズ外に dragBox をドラッグできるように、Drawing のサイズを動的に変更できるようにしたいと考えています。現在、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;

} 

提供された仮想空間にドロップするようにドラッグボックスをドロップするにはどうすればよいですか?

ブルース

4

1 に答える 1

1

解決しました!

dragUpdated では、これでうまくいきました。

 _drawHintPoint = [[self superview] convertPoint:[sender draggingLocation] fromView:nil];

ドラッグ位置をスクロール ビューの座標に変換する必要があります。上記の行の [self superview] は、NSClipRect を指します。

于 2013-06-01T11:32:53.087 に答える