我可以使用该窗口内的对象移动窗口吗?

Don*_*van 3 cocoa window movable

在Cocoa中是否可以通过拖动窗口内的对象来移动窗口?例如:我在窗口内有一个webview,大窗口,所以setMovableByWindowBackground显然不起作用.有没有办法点击并拖动Web视图并移动整个窗口?

kub*_*ubi 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];
}
Run Code Online (Sandbox Code Playgroud)

我从这里得到的:http://www.cocoadev.com/index.pl?SetMovableByWindowBackground