问题
I tried -setFrame:display:
and -windowDidMove:
but they are not sent while moving window.
回答1:
If You want to track NSWindow
live moving, it's not possible by default You’ll have to do it on your own. It's possible to get notification when NSWindow
is started to drag (move) with NSWindowWillMoveNotification
or ended dragging (moving) - NSWindowDidMoveNotification
.
Take a look at these examples they can help You to solve live window moving problem:
1. Example:
Description: Very short category on NSWindow that makes windows post NSWindowDidMove notifications continuously during dragging (much like NSWindowDidResizeNotification behaves). Uses a secondary thread and behavior can be toggled.
Download link.
2. Example:
Project download link.
回答2:
You can register an observer for NSWindowDidMoveNotification.
来源:https://stackoverflow.com/questions/10495037/how-to-receive-notifications-when-moving-window-by-mouse