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

  • SEARCH
  • Home
  • 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 8661453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:30:06+00:00 2026-06-12T16:30:06+00:00

I just started a brandnew project GrafLaboratory to do some experimenting on drawing in

  • 0

I just started a brandnew project GrafLaboratory to do some experimenting on drawing in NSView.
I added a custom view to the main window and configured it to adopt it´s size when the window changes it´s size.

I modified my InitFrameWith to this:

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSRect r = [self bounds];
    }

    return self;
}

When I start my new app the first time and ask for [self bounds] I get the correct value: {{0, 50}, {600, 450}}. I then change the size of the window by dragging with the mouse. When restarting my app initWithFrame returns the same value: {{0, 50}, {600, 450}}.

But I the new changed size. I already tried several things but without success.

Any clues what I´m doing wrong?

Thanks, Ronald

  • 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-06-12T16:30:07+00:00Added an answer on June 12, 2026 at 4:30 pm

    The initWithFrame is only relevant when you initialize the object within a frame.

    If it’s a custom UIView with custom drawing, then look at:

    - (void)drawRect:(NSRect)frame
    

    That will get called when setNeedsDisplay is called and/or the view is resized.

    With some custom views, one thing I’ve done in initWithFrame is to set the autoresize masks:

        // subviews autoresize
        [self setAutoresizesSubviews:YES];   
        // set resize masks (springs)
        [self setAutoresizingMask:(NSViewMaxXMargin | NSViewMinXMargin |
                                  NSViewMaxYMargin | NSViewMinYMargin |
                                  NSViewHeightSizable | NSViewWidthSizable)];
    

    Then in both init and drawRect, I call my layoutViews metod if the rect has changed:

    - (void)drawRect:(NSRect)frame {
        ...
        // called on resize.  on init, delegate isn't hooked up so we'll skip
        if (!NSEqualRects(_prevRect, [self bounds]))
        {
            [self layoutViews];
        }
    
        // stash away rect for comparison so layout view code only happens when the rect changes
        _prevRect = [self bounds];
    

    My layoutViews has custom layout logic.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started my first WCF rest project and would like some help on what
I've just started a brand new rails project and the first task I'm trying
Just started my first MVC 2.0 .net application. And I set up some default
Just started on a new project and opened up a 1600 line web.config file
Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter. I need some
Just started looking at some MVC JS framework / library and most of them
Just started a tutorial in SQL for beginners. I'm doing some exercises now and
I'm trying to get started with Phonegap. I have added some code to applicationDidFinishLaunching
Just started doing some code porting from .Net CF to Blackberry JDE 4.6.1. But
Just started working on a c project. Need help with passing function pointers/macro functions/etc.

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.