1

I was trying to reposition the NSWindowButtons (NSWindowCloseButton etc., aka "Traffic Lights") with code like the following:

NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton];
[closeButton setFrame:newFrame];
[closeButton removeFromSuperview];
[window.contentView addSubview:closeButton];

The reposition works without problems. However, as soon as the window finished loading (became key), the tracking area was still at its old position (where those buttons were). Once I resized the window, the tracking area seemed to be updated to the correct (current) location.

I've tried things like [closeButton updateTrackingAreas], but according to this answer it shouldn't work anyways.

Are there more direct/correct ways to fix this issue without subclass NSView/NSWindow?

Update:

This is what I currently use to "fix" the issue: (via NSWindowDelegate)

- (void)windowDidBecomeMain:(NSNotification *)notification
{
    NSRect frame = [self.window frame];
    frame.size = NSMakeSize(frame.size.width, frame.size.height+1.f);
    [self.window setFrame:frame display:NO animate:NO];
    frame.size = NSMakeSize(frame.size.width, frame.size.height-1.f);
    [self.window setFrame:frame display:NO animate:YES];
}

The window will then be resized without refreshing the actual frame, to force update the tracking areas.

Community
  • 1
  • 1
Cai
  • 3,609
  • 2
  • 19
  • 39

0 Answers0