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.
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.
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)
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):
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.