检测重叠的Windows

问题描述 投票:0回答:1

有什么方法可以检测我的应用程序中的窗口是否重叠?

objective-c macos cocoa
1个回答
2
投票

使用NSApp中的窗口

//find overlaps
for (NSWindow *w in [NSApp windows]) {
   for (NSWindow *w2 in [NSApp windows]) {
      if (CGRectIntersectsRect(w.frame, w2.frame) || CGRectIntersectsRect(w2.frame, w.frame)) {
          // add the pairs w & w2 up in a NSDictionary with w as key and an array of w2s it intersects 
          // ....
      }
   }
}

//handle all the queued overlaps....
© www.soinside.com 2019 - 2024. All rights reserved.