Question

I've a NSWindow using Autolayout. It just contains a single view where a label (NSTextField) is placed. The text in this label is dynamic and changes when my application is running. When a longer text is inserted my window perfectly resize because of my vertical and horizontal constraints.

My problem is, that my window should be positioned in the upper right corner of the screen (just under the menu bar). When my window is resized when satisfy my constraints, I need to re-position my window on the screen.

What is the best approach for this?

Was it helpful?

Solution

Register the windowDidResizeNotification in your applicationDidFinishLaunching: method to handle the resize event as:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:NSWindowDidResizeNotification object:nil];    //register resize notification

}

Then in the notification handler method, use the code you were previously using to set the window to top right.

- (void)handleNotification: (id) sender
{
    //code to set window to top right corner
}

A very recent answer of mine could help you in this: https://stackoverflow.com/a/19677527/1987246

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top