Split view - the code side.

Hello, I need your help for another feature of cocoa.

I have a split view, horizontal delimiter, in my window. I have an image well on the top custom view and a text scroll view in the bottom custom view. When I drag the delimiter, the image resizes until it disappears, and the text grows accordingly, with the scroll bar updating. I don’t dare to imagine programming this myself. :slight_smile:

I wanted to know two things:

a) How to make programmatically the top custom view shrink to reach zero-height (“disappear”)? Ideally with a smooth effect.
b) How to make to make programmatically the top custom view fit the image height?

Is it possible in ASOC? One of the difficulties is that the origin of the screen is left, bottom. When I left my Mac years ago, QuickDraw started on the left, top. :confused:

Regards

It’s possible. Moving the divider is just a matter of calling setPosition:ofDividerAtIndex: – you can get the size of everything you need and do the sums. Tedious perhaps, but relatively straight forward.

For animation, you have to use the animator proxy object described in NSAnimatablePropertyContainer Protocol. So instead of something like (untested):

tell splitView to setPosition_ofDividerAtIndex_(x, 0)

you’d use:

tell splitView's animator() to setPosition_ofDividerAtIndex_(x, 0)

Shane,

I tried using the animator, and it didn’t work. Is the NSSplitView’s divider’s position not animatable?

The inelegant way did work:

on Collapse()
		set pos to 130
		repeat 65 times
			set pos to pos - 2
			sv's setPosition_ofDividerAtIndex_(pos, 0)
			sv's |display|()
		end repeat
	end Collapse

Where 130 was the starting position of my divider (or nearly so, there doesn’t seem to be a method to get its position).

Ric

It looks like it’s not – only frame and size, I guess.

I guess you’d need to get the frame of its subviews and work it out from there.

If you only want to have the text view expand, and have the image view get covered up (in code), you can just have a half height text view under your image view and then change the frame of the scroll view using an animator with a line like this (the 320 I figured out in IB just by expanding it to the top of my window – if your window is resizable, you would have to do something more sophisticated):

scrollview's animator's setFrameSize_({|width|:sv's frame()'s |size|()'s |width|, height:325})

Of course, this wouldn’t be useful if you want the user to be able to resize by dragging the divider.

Ric

I have tried an other approach to make the top view disappear: I hide it - in order to make IB binding with the preferences possible (of course I don’t get the animating effect).

But it doesn’t work, because from IB, you cannot tell the view to display() automatically, so it leaves a grey area until the next update.

So I did it by code ” in a handler on ShowHideImage_(aNotification) and removed it from the preferences.

The “smooth effect” examples found on the Web tell enough that the animator() does not work. And the bypassing coding are dozens of Objective-C lines… I resign.

More, I get strange effects with the image well contained in the top custom view. The image resizes, but if I drag the divider too fast, the top of the image sticks to the upper side of the custom view.

I thought it would have been more simple. :confused:

Regards,