NSView lock position on frame resize.

Discussion in 'Mac Programming' started by Avizzv92, Dec 14, 2010.

  1. Avizzv92 macrumors regular

    Joined:
    Mar 23, 2008
    #1
    I have a custom NSView, when I adjust the frame's size the origin ends up moving. What I want is the view to be locked from the top left position so that when I re-size the view expands right and down while holding its position. Sorry if this is confusing, think of it like the left alignment for text sort of...

    Also, this view is being created and displayed strictly with code and not Interface Builder.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Use setAutoresizingMask: with NSViewWidthSizable and NSViewHeightSizable.
     
  3. Avizzv92 thread starter macrumors regular

    Joined:
    Mar 23, 2008
    #3
    I wasn't looking for it to re-size with the window, and the position still doesn't remain constant when I change the frame of the view.

    Say I have a square that is on the edge of the window and its 50x50 in size. I make the new frame for it 250x250, it ends up enlarging it but half of it ends up expanding outside the view of the window. Hope this makes sense...
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    I think you're misunderstanding what the origin of the view actually is. In Cocoa, the origin is the bottom left. So when you adjust the view's height, the bottom of the view will stay the same and the top will change.

    To do what you want to do, you need to adjust the frame height and origin at the same time.
     
  5. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #5
    If you override -isFlipped, the upper left corner of your view's bounds rectangle will be 0.0, 0.0 . However, if your view is drawing NSImages, you must set them to be flipped wholes you are drawing them in your view.
     

Share This Page