3

Cocoaで、ウィンドウ内にあるオブジェクトをドラッグしてウィンドウを移動することは可能ですか?例:ウィンドウ内にウィンドウと同じ大きさのWebビューがあるため、setMovableByWindowBackgroundは明らかに機能しません。Webビューをクリックしてドラッグし、ウィンドウ全体を移動する方法はありますか?

4

1 に答える 1

5

もちろん、を使用してマウスの動きを追跡する必要がありますmouseDragged。これに似たものが機能するはずです:

- (void)mouseDragged:(NSEvent *)theEvent
{
   NSPoint currentLocation;
   NSPoint newOrigin;

   NSRect  screenFrame = [[NSScreen mainScreen] frame];
   NSRect  windowFrame = [self frame];

    currentLocation = [NSEvent mouseLocation];
    newOrigin.x = currentLocation.x - initialLocation.x;
    newOrigin.y = currentLocation.y - initialLocation.y;

    // Don't let window get dragged up under the menu bar
    if( (newOrigin.y+windowFrame.size.height) > (screenFrame.origin.y+screenFrame.size.height) ){
        newOrigin.y=screenFrame.origin.y + (screenFrame.size.height-windowFrame.size.height);
    }

    //go ahead and move the window to the new location
    [self setFrameOrigin:newOrigin];
}

ここから取得したもの:http://www.cocoadev.com/index.pl?SetMovableByWindowBackground

于 2009-12-22T12:54:07.783 に答える