More constraints confusion

  • I put an NSImageView into a window. I want the NSImageView's frame to always fill the window content frame.

    When I dropped it in, IB gave it a width and height constraint that I can't edit. I sized it to fit the window, and it also added leading and trailing space constraints.

    I explicitly set top and bottom constraints.

    But the width & height constraints can't be edited. If I promote them to user constraints, and then try to delete them, they just come back.

    Why does IB think they are necessary?

    --
    Rick
  • No, pinning is not what I want. That's what I'm trying to avoid. IB in insisting on pinning the width and the height.

    I think it assumes the NSImageWell MUST have a static size, rather than allow it to resize. I'm able to put an NSView without this problem.

    On Apr 25, 2013, at 16:48 , Caylan Larson <i...> wrote:

    > Rick,
    >
    > Search the help menu for "pin" and see if pinning the height or width gets you to where you need to be.
    >
    > Caylan
    >
    > On Apr 25, 2013, at 6:39 PM, Rick Mann <rmann...> wrote:
    >
    >> I put an NSImageView into a window. I want the NSImageView's frame to always fill the window content frame.
    >>
    >> When I dropped it in, IB gave it a width and height constraint that I can't edit. I sized it to fit the window, and it also added leading and trailing space constraints.
    >>
    >> I explicitly set top and bottom constraints.
    >>
    >> But the width & height constraints can't be edited. If I promote them to user constraints, and then try to delete them, they just come back.
    >>
    >> Why does IB think they are necessary?
    >>
    >> --
    >> Rick

    --
    Rick
  • IB adds constraints to both the NSImageView and its superview. I believe
    that this is why deleting a constraint causes it to come back (it's in two
    views).

    Here's what I recommend:
    - Delete the NSImageView which will also delete the associated constraints.
    - Drag a new NSImageView to the window (i.e. the main view of the window).
    - Resize the NSImageView to fit inside the frame of its containing view.
    - Select NSImageView, by double clicking on the NSImageView in the list of
    objects. Now, from the Editor menu select "Align -> Horizontal Center in
    Container" and "Align -> Vertical Center in Container." (You can also do
    that by clicking on the leftmost icon of the constraints control at the
    bottom right of the IB view.)

    That should do it. Adding those alignment constraints deleted the trailing
    and bottom constraints.

    Chuck

    On 4/25/13 4:39 PM, "Rick Mann" <rmann...> wrote:

    > I put an NSImageView into a window. I want the NSImageView's frame to
    > always fill the window content frame.
    >
    > When I dropped it in, IB gave it a width and height constraint that I
    > can't edit. I sized it to fit the window, and it also added leading and
    > trailing space constraints.
    >
    > I explicitly set top and bottom constraints.
    >
    > But the width & height constraints can't be edited. If I promote them to
    > user constraints, and then try to delete them, they just come back.
    >
    > Why does IB think they are necessary?
    >
    > --
    > Rick
  • On Apr 25, 2013, at 6:50 PM, Rick Mann <rmann...> wrote:

    > No, pinning is not what I want. That's what I'm trying to avoid. IB in insisting on pinning the width and the height.
    >
    > I think it assumes the NSImageWell MUST have a static size, rather than allow it to resize. I'm able to put an NSView without this problem.

    Pinning *is* what you want. Do each of "Pin Leading/Trailing/Top/Bottom Edge To Superview", and then the height and width constraints should become deletable.

    If it still won't let you delete them even after that, then just give them a low enough priority in the Inspector that they cease to matter.

    Charles
  • On Apr 25, 2013, at 18:30 , Charles Srstka <cocoadev...> wrote:

    > Pinning *is* what you want. Do each of "Pin Leading/Trailing/Top/Bottom Edge To Superview", and then the height and width constraints should become deletable.

    Sorry, I misunderstood. Yes, I had already pinned the Leading/Trailing/Top/Bottom Edges To Superview.

    > If it still won't let you delete them even after that, then just give them a low enough priority in the Inspector that they cease to matter.

    Like I said, I think this is something about Image Well (NSImageView). In its size inspector, it has three pre-defined sizes in a popup. I think IB is trying to require that it be of fixed size. I finally just gave up and wrote code to stick my image into the CALayer of an NSView, which does not exhibit this behavior in IB.

    --
    Rick
  • On Apr 25, 2013, at 8:35 PM, Rick Mann <rmann...> wrote:

    > On Apr 25, 2013, at 18:30 , Charles Srstka <cocoadev...> wrote:
    >
    >> Pinning *is* what you want. Do each of "Pin Leading/Trailing/Top/Bottom Edge To Superview", and then the height and width constraints should become deletable.
    >
    > Sorry, I misunderstood. Yes, I had already pinned the Leading/Trailing/Top/Bottom Edges To Superview.

    Perhaps try it again. IB can be a little wonky sometimes WRT constraints; perhaps re-adding the constraints for the four edges to the superview again, and see if it makes IB realize that the height/width constraints aren't needed.

    >> If it still won't let you delete them even after that, then just give them a low enough priority in the Inspector that they cease to matter.
    >
    > Like I said, I think this is something about Image Well (NSImageView). In its size inspector, it has three pre-defined sizes in a popup. I think IB is trying to require that it be of fixed size. I finally just gave up and wrote code to stick my image into the CALayer of an NSView, which does not exhibit this behavior in IB.

    I tried it myself in IB with an NSImageView after reading your original post, and was not able to reproduce this behavior, so that's not it.

    Charles
  • On 4/25/13 6:35 PM, "Rick Mann" <rmann...> wrote:

    > On Apr 25, 2013, at 18:30 , Charles Srstka <cocoadev...>
    > wrote:
    >
    >> Pinning *is* what you want. Do each of "Pin Leading/Trailing/Top/Bottom
    >> Edge To Superview", and then the height and width constraints should
    >> become deletable.
    >
    > Sorry, I misunderstood. Yes, I had already pinned the
    > Leading/Trailing/Top/Bottom Edges To Superview.
    >
    >> If it still won't let you delete them even after that, then just give
    >> them a low enough priority in the Inspector that they cease to matter.
    >
    > Like I said, I think this is something about Image Well (NSImageView). In
    > its size inspector, it has three pre-defined sizes in a popup. I think IB
    > is trying to require that it be of fixed size. I finally just gave up and
    > wrote code to stick my image into the CALayer of an NSView, which does
    > not exhibit this behavior in IB.

    This would happen if you had the Image Cell selected instead of the Image
    Well. If you shift-control click on the IB object that you're trying to
    select, you'll get a popup menu. Make sure that you select Image Well not
    Image Cell.

    Chuck
  • On Apr 26, 2013, at 1:35 AM, Rick Mann <rmann...> wrote:

    >
    > On Apr 25, 2013, at 18:30 , Charles Srstka <cocoadev...> wrote:
    >
    >> Pinning *is* what you want. Do each of "Pin Leading/Trailing/Top/Bottom Edge To Superview", and then the height and width constraints should become deletable.
    >
    > Sorry, I misunderstood. Yes, I had already pinned the Leading/Trailing/Top/Bottom Edges To Superview.

    So the NSImageView is the _only_ thing in the window? Because the behavior you're describing sounds like what happens when IB determines that you don't have enough constraints to give every view in the window a well-defined size.

    --Kyle Sluder
previous month april 2013 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Go to today