0

Is there any way I can detect if windows from my application are overlapping ?

user57368
  • 5,675
  • 28
  • 39
cocoa coder
  • 214
  • 1
  • 3
  • 15
  • 1
    Check if http://stackoverflow.com/questions/11473189/multiple-uiviews-overlapping helps you. – ott-- Nov 11 '12 at 20:17

1 Answers1

2

use the windows in 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....
Andrew
  • 7,630
  • 3
  • 42
  • 51
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Great, thanks ! Is there also a way to get a notification or something when one window intersect another? Maybe rectDidIntersect or something, so it won't have to poll it all the time ? – cocoa coder Nov 12 '12 at 22:17
  • 1
    well, there are notifications sent when they move or resize. you could sign up for those and then look at the windows when a notification comes in – Daij-Djan Nov 13 '12 at 07:32