views:

24

answers:

1

This is a rather simple question and I'm sure it's not to hard, but the question is...

I have a NSpanel that is centered and then after the centering I need to do a transform to move the window down on the Y coordinate while maintaining the centered X coordinate.

Is NSAffineTransform the correct way to go about this and does anyone have an example or idea of what I would need to do in order to move that nspanel down. Thanks again all.

  NSRect windowFrame = NSMakeRect(0, 0, 500, 100);

    NSRect windowFrame2 = NSMakeRect(0, 100, 500, 150);

    window = [[HUDWindow alloc] initWithContentRect:windowFrame 
                                          styleMask:NSBorderlessWindowMask 
                                            backing:NSBackingStoreBuffered 
                                              defer:NO];
    [window setLevel:kCGDesktopWindowLevel + 1];

    window2 = [[Mainbox alloc] initWithContentRect:windowFrame2 
                                          styleMask:NSBorderlessWindowMask 
                                            backing:NSBackingStoreBuffered 
                                              defer:NO];
    [window2 setLevel:kCGDesktopWindowLevel + 1];
    [window center];
    [window2 center];

^ piece of code I have in my project

+2  A: 

No, just reset the frame.

- (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews animate:(BOOL)performAnimation

Warren Burton
I can kinda see where you are going with this but I don't really know how I would go about resetting the frame. I have placed my NSRect code and the allocation code for the classes that draw the windows.What would I have to include in the void to make both windows move to certain Y coordinates?I Appreciate your patience. I haven't work as much in making desktop cocoa apps as I have in making iphone stuff
Rugluds
Rugluds: You don't *implement* that method, you *call* that method. Just send the `setFrame:display:animate:` message to your window, passing the desired frame and options. The window already knows how to move itself. See the docs: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html#//apple_ref/occ/instm/NSWindow/setFrame:display:animate:
Peter Hosey
Rugluds: Sorry, I wasnt clear enough. As Peter says get hold of your current frame rect and then adjust the origin.y and pass it back via that NSWindow method e.g `[window2 setFrame:modrect display:YES animate:YES];`
Warren Burton
Thanks Warren for the example and help.
Rugluds