美文网首页
MacOS开发 鼠标拖动窗口事件

MacOS开发 鼠标拖动窗口事件

作者: drmi | 来源:发表于2018-11-06 09:39 被阅读61次

参考官方文档:
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/WinPanel/Tasks/SizingPlacingWindows.html

NSWindow有一个属性movable,默认是YES,此时属性movableByWindowBackground是可用的;当movable被置为NO,movableByWindowBackground属性被忽略。movableByWindowBackground如果为YES,则用户可通过点击并且拖拽window的背景实现拖动窗口。但是有种情况会失效,需要用以下代码(继承NSView的自定义类)覆盖mouseDownCanMoveWindow方法,并且返回YES。我遇到的情况是,我在window的view上添加了一个自定义的NSSplitView类CustomSplitView,导致鼠标拖动背景事件无效,因此在类CustomSplitView添加此方法即可解决拖动不了的问题。
/**
The user can generally reposition windows by dragging only the title bar. If you want users to be able to drag your window by clicking elsewhere, you should override mouseDownCanMoveWindow so that it returns YES in any views that you want to be draggable window regions. The methods isMovable and setMovable: determine whether the user can move the window by clicking in its title bar or background.

@return
*/
-(BOOL)mouseDownCanMoveWindow{
[super mouseDownCanMoveWindow];
return YES;
}

相关文章

  • MacOS开发 鼠标拖动窗口事件

    参考官方文档:https://developer.apple.com/library/archive/docume...

  • Javascript知识整理——拖放

    拖放事件 拖动某元素时,将依次触发下列事件(被拖动元素): dragstart按下鼠标并开始移动鼠标时在被拖动元素...

  • Mac 开发 NSWindowStyleMaskResizabl

    NSWindow 窗口随着鼠标拖动放大缩小控制方法

  • 原生js鼠标拖拽效果

    常用的鼠标事件有onmousedown(鼠标按下)、onmousemove(鼠标拖动)、onmouseup(鼠标弹...

  • 三、控制窗口

    一、拖动窗口Windows命名空间中,有一个拖动窗口的方法:DragMove(),鼠标按住标题栏时,调用此方法,即...

  • macOS 鼠标事件

    NSResponder NSEvent https://www.jianshu.com/p/5c8d2a8bfad...

  • macOS开发之自定义拖动窗口

    我们平时开发中NSWindow有个方法是可以设置点击窗口背景拖动窗口的,就是下面的这个方法,使用起来也比较方便,可...

  • Websocket, SetTimeout 与页面崩溃

    问题 用户在RDP的使用中有时候会用鼠标在打开的PDF文档中拖动选择大块的文字和图片。当用户鼠标拖动到PDF窗口的...

  • 第二章:什么是Shell

    1. 关于鼠标和光标 在terminal窗口下,如果你按下鼠标左键,==沿着文本拖动鼠标==(或者双击一个单词)高...

  • Maya(四) 视图操作

    旋转视图: ALT + 拖动鼠标左键 缩放视图: ALT + 拖动鼠标右键 平移视图: ALT + 拖动鼠标中键 ...

网友评论

      本文标题:MacOS开发 鼠标拖动窗口事件

      本文链接:https://www.haomeiwen.com/subject/ucyyxqtx.html