How to snap an NSWindow to a grid
How can I snap an NSWindow to a grid? Any good algorithms, tutorials that are rec开发者_C百科ommended?
If you just want to monitor you app's windows its easy to just monitor the own windows locations and "override" their locations as soon as they come to a grid boundary. You might want to checkout the KVO documentation for observing NSWindow
properties.
What I think you actually want to do is monitor ALL windows, including those from other apps. If so, have a look at Apples Accessibility APIs.
Keep in mind when you use AX APIs you have to either enable accessibility support in the system preferences or authorize your app!
Update:
Example: http://toxicsoftware.com/snappingwindow_cocoa_source_code/
精彩评论