Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6016329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:58:00+00:00 2026-05-23T02:58:00+00:00

I have a NSWindowController with a setCurrentView method in which I use the following

  • 0

I have a NSWindowController with a setCurrentView method in which I use the following code to resize the window to the new view’s size.

[self resizeWindowForContentSize: [newView frame].size];

NSView *contentView = [[self window] contentView];
NSDictionary *ani = [NSDictionary dictionaryWithObject:transition 
                                                forKey:@"subviews"];
[contentView setAnimations:ani];    
[[contentView animator] replaceSubview:currentView with:newView];

Edit: Added the resizeWindowForContentSize I found on CocoaDev.

- (void)resizeWindowForContentSize:(NSSize) size {
    NSRect windowFrame = [NSWindow contentRectForFrameRect:[[self window] frame]
        styleMask:[[self window] styleMask]];
    NSRect newWindowFrame = [NSWindow frameRectForContentRect: 
        NSMakeRect( NSMinX( windowFrame ), NSMaxY( windowFrame ) - size.height, size.width, size.height )
    styleMask:[[self window] styleMask]];
    [[self window] setFrame:newWindowFrame display:YES animate:[[self window] isVisible]];
}

The problem I’m having is that as you switch between views (using NSToolbar) the views begin to move around in the contentView. Over time they actually draw further and further away until eventually there is just a blank view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:58:01+00:00Added an answer on May 23, 2026 at 2:58 am

    Instead of using the class methods:

    +[NSWindow frameRectForContentRect:styleMask:]
    +[NSWindow contentRectForFrameRect:styleMask:]
    

    use the instance methods:

    -[NSWindow frameRectForContentRect:]
    -[NSWindow contentRectForFrameRect:]
    

    instead. The instance methods take toolbars into account, and should be used whenever you have an NSWindow instance — which you do via [self window].

    For example, assuming that’s the problem with your -resizeWindowForContentSize: method:

    - (void)resizeWindowForContentSize:(NSSize) size {
        NSWindow *window = [self window];
    
        NSRect windowFrame = [window contentRectForFrameRect:[window frame]];
        NSRect newWindowFrame = [window frameRectForContentRect:
            NSMakeRect( NSMinX( windowFrame ), NSMaxY( windowFrame ) - size.height, size.width, size.height )];
        [window setFrame:newWindowFrame display:YES animate:[window isVisible]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: @interface AXWindowController : NSWindowController { IBOutlet NSTextField *text; IBOutlet
Suppose you have a window nib, owned by a NSWindowController which loads the nib.
I have an NSWindowController subclass called _PreferencesWindowController with the following implementation - @synthesize window;
I have a main window controller which is a NSWindowController (golden rectangle) with a
I have an NSDocument which has the following structure: @interface MyDocument : NSDocument {
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
Have the following code. The height is variable so the height of the floating
Have the following scenario. I have a few form, which essentially have a few
In an application (OS X 10.6.7) I have a NSWindowController subclass which is initialized
Have you guys had any experiences (positive or negative) by placing your source code/solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.