cocoa - 我可以使用窗口内的对象来移动窗口吗?

标签 cocoa window movable

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

最佳答案

当然,您只需使用 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

关于cocoa - 我可以使用窗口内的对象来移动窗口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1946185/

相关文章:

objective-c - 在 10.6 下调用 Finder 的 Scripting Bridge 返回值不正确(但不会引发错误)

c++ - 查找窗口并更改其名称

java - 制作一套未装饰的可移动选项卡面板

objective-c - 如何在 Objective-C 中更改 MacOS 中文件的图标?

objective-c - Cocoa - 内存问题 - NSTableView

java - 调整浏览器窗口大小后无法从元素获取文本(Chrome)

asp.net-mvc-3 - mvc3检测网站(应用程序)正在关闭

javascript - 如何制作多个可移动元素

c# - 在 C# 中用鼠标拖动来移动控件

cocoa - TableView 中的自定义 NSTextField : how do I know if the row is selected to change the background color?