Question

It is posible to configure splitview with 3 subviews through auto layout constraints like in mail.app? What i mean: when the user resizing the window only rightmost subview change it size, when the user drags the divider between the leftmost and middle subviews, only left and right subviews changes its size and when the user drags the divider between the middle and the right subviews only these subviews change size. If it is possible how to do the. I think that this task may be performed by constraints priority, but i confused with that. Thanks!

Was it helpful?

Solution

I found a solution without using auto layout constraints. I'm working with Rubymotion so my solution is in Ruby but it can be easily translated in Objective-C.

First of all, to get only left and right subviews changing their size when the user drags the divider between the left and the middle subviews, I created two nested NSSplitView, the second one into the right part of the first one.

The last point mentionned in the question, that is to say when the user drags the divider between the middle and the right subviews only these subviews change size is the default behavior of an NSSplitView so nothing to do here.

Finally, to get only rightmost subview changing its size when the user resizes the window, I implemented the splitView:resizeSubviewsWithOldSize: delegate method:

def splitView(splitView, resizeSubviewsWithOldSize:oldSize)
  sv1 = splitView.subviews[0]
  sv2 = splitView.subviews[1]

  leftFrame = sv1.frame
  rightFrame = sv2.frame
  newFrame = splitView.frame

  leftFrame.size.height = newFrame.size.height
  rightFrame.size.height = newFrame.size.height

  leftFrame.origin = NSMakePoint(0,0)
  ## 1 is the NSSplitView divider width
  rightFrame.size.width = newFrame.size.width - leftFrame.size.width -  1
  rightFrame.origin.x = leftFrame.size.width + 1

  sv1.setFrame(leftFrame)
  sv2.setFrame(rightFrame)
end

And voilà! It took me a while to make it work so I hope it will save a few time to other people.

OTHER TIPS

With auto layout you can set the holding priority of each divider in an NSSplitView. You can do this in code with the delegate methods or in interface builder in Xcode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top