Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with autolayout on NSScrollView's document view
    primarykey
    data
    text
    <p>I'm trying to find the best way to use Lion's autolayout to make this simple window containing a scrollable view with a centered image and a border around it. See my awesome ascii art:</p> <pre><code>+==============+ | || | XXXXXX || | XXXXXX || | XXXXXX || | | +--------------+ </code></pre> <p>The NSScrollView's document view is a flipped NSView subclass that draws a background pattern, and inside that I add an image that the user chooses (ie. indeterminate size). When adding the image view, I give it constraints to center it in the document view. The document view itself is given constraints saying it wants to be slightly larger than the loaded image. What I'm wanting is the obvious behavior: on loading an image larger than the scollview, the scrollers become active, on resizing the window the scrollers activate / deactivate normally.</p> <p>However, when loading a large image I'm seeing is the document view expanding all right, but the scroll view &amp; window expand with it! After that point the window doesn't permitting resizing any smaller. Obviously I'm not doing it right, but I can't see why.</p> <p>I tried changing the priority of the constraints of the document view, anything above NSLayoutPriorityWindowSizeStayPut and the window expands as above (makes sense I guess), but anything lower and the document view never resizes, resizing the window smaller works but the scrollers aren't enabled.</p> <p>Does anyone know if there are other priorities I need to set elsewhere, or additional constraints I need, or a different approach altogether .. should I instead be setting the document view's "intrinsic size"? Also pointers to any autolayout open source / sample code I haven't seen yet would be cool.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI'm trying to figure out how to use autolayout to make the amazing ascii art view hierarchy you mentioned in your post. I start with an NSImageView and then choose the Embed in Scroll View option. But then nothing seems to work after than, the centred constraints on the NSImageView in the scroll view are ignored. Any chance I could take a look at a barebones project which hows how to do this with constraints?
      singulars
    2. COI didn't at-name you last time so maybe you didn't notice. Updating to Xcode 5 seems to have solved the bulk of the problems, however, I still cannot get the image view to be centered in the scroll view.
      singulars
    3. COSorry that I didn't see your earlier comment. Sadly, I no longer have that project. Like my answer below says, the nib only has a `NSScrollView`, the view hierarchy containing the `NSImageView` being created at runtime so that the `translates..` property can be set to NO. I can't remember what the contraints were, but I don't think they were tricky. Probably a `NSView` superview to the `NSImageView` having width/height constraints set with `>=` relation to the image size (known at the time the constraint made at runtime), then ones for centering the NSImageView in its superview.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload