If a NSView uses autolayout, do all of its subviews also need to use autolayout for positioning?

Posted by boyfarrell on Stack Overflow See other posts from Stack Overflow or by boyfarrell
Published on 2013-10-19T08:29:38Z Indexed on 2013/10/19 9:54 UTC
Read the original article Hit count: 155

Filed under:
|
|

I have a view in a window, the position and size of the view are calculated with autolayout. The view has a subview, a draggable NSView subclass. It is really easy to make a NSView "draggable" by overriding -mouseDown: and -mouseDragged: and changing the frame of the view directly.

The view hierarchy is as follows, Draggable subview

What is the best way of making the subview draggable in this case?

For example,

  1. Is it possible for the subview to not use autolayout, so that it can be positioned by changing the frame directly? i.e. the window positions the main view, but then autolayout does not layout the subview inside the main view. Or to all views in the hierarchy need to use autolayout.

  2. When I have used autolayout before, I have used it to make "fixed" layout that respond to resizing. But dragging a view with a mouse does't seems like a natural use case for autolayout.

© Stack Overflow or respective owner

Related posts about osx

Related posts about cocoa