NSView positioning not correct on sheet?

Discussion in 'Mac Programming' started by turner296, Jan 1, 2009.

  1. turner296 macrumors newbie

    Jan 1, 2009
    I've had the most stressful 2 days, and I was wondering if there's any experts out there that can tell me a bit about resizing and positioning of NSViews.

    Here's what I'm trying to achieve;
    I have a login prompt that slides down within a sheet, after a successful login the sheet resizes itself to be smaller so that a little message says that the user is correctly logged in. The user details are saved within a file and when the application starts up again it automatically logs in the user with the details saved.

    The problem;
    The positioning of the NSView which contains the success message is completely out of position, therefore some controls are off the frame of the sheet. I've being trying to get this to work and I know all my NSRect origin and size's are correct for the NSView to display correctly within the sheet but something somewhere is changing them or I simply haven't coded it right (I'm sure its the second option, but we all don't like to be proved wrong :p)

    Could someone please take a look at the below code and see what I'm doing wrong?

     * Changes the login sheet's view
    - (void)changeLoginSheetView:(NSView *)view animate:(BOOL)animate
    	NSView * blank = [[[[NSView alloc] init] retain] autorelease];
    	NSRect current = [loginWindow frame];
    	NSRect new;
    	[loginWindow setContentView:blank];
    	 * Work out frame stuff
    	new.origin.x = current.origin.x;
    	new.origin.y = current.origin.y + (current.size.height - [view frame].size.height);
    	new.size.width = current.size.width;
    	new.size.height = [view frame].size.height;
    	 * Show new view
    	[loginWindow setFrame:[view frame]
    	[loginWindow setContentView:view];
    The pictures below are whats happening when the application is in operation, and the other picture is how Ive laid it out in Interface Builder. Im sure you's can judge which one is the correct display!

    Thanks in advance for all your help!!! :D:D:D:D:D:D

    Attached Files:

  2. kainjow Moderator emeritus


    Jun 15, 2000
  3. turner296 thread starter macrumors newbie

    Jan 1, 2009
    Yes, when I resize the NSView in interface builder every control stays put, so why is it when its resized programatically the controls are pushed down. Ive read the programming guide from the apple developer center on NSViews but still can't get my head around whats causing it to this.

    Its really frustrating me, its making my application look real unprofessional :(

Share This Page