Re: Expanding NSScrollView
Re: Expanding NSScrollView
- Subject: Re: Expanding NSScrollView
- From: Quincey Morris <email@hidden>
- Date: Tue, 21 Jul 2009 14:51:53 -0700
On Jul 21, 2009, at 12:55, Andrew Shamel wrote:
I'm looking for it to expand as its documentView expands.
The scrollviews are contained in a custom view called CardView,
which is itself inside a scrollview which I am happy to have act in
the usual fashion as the CardView gets taller and shorter as a
result of its expanding and contracting contents. The custom
scrollviews are arranged in a vertical stack within the CardView,
and need to retain the same relative distance to one another as they
expand and contract. I believe I have this relative change in
position handled. It's finer control over the expansion of the
scrollview itself that I'm after.
I have two configurations: one containing an NSTextView, and one
containing an NSTableView.
For the one containing the textview, i want the scrollView to expand
as the textView does (rather than letting the textView become hidden
inside the scrollView), up until the textView has four lines of text
at which point, normal scrolling behavior starts (i.e., the content
which will not be in view is hidden and the scrollbars activate).
For the one containing the tableview, I'm looking for similar
behavior, only replacing "four lines of text" with "four rows in the
table."
I have managed to implement this behavior manually, based on
checking the size of the content and the size of the scrollview each
time the data is changed (i.e., implementing the textDidChange:
delegate method, and monitoring the tableview's data source for new
rows)
Ack! That seems far too complicated.
You can have your window controller (or whatever equivalent controller
you're using) register via 'addObserver:selector:name:object:' to be
notified when the NSTextView or NSTableView frame changes. (Note that
you have to call 'setPostsFrameChangedNotifications:YES' on those
views to be able to get these notifications.)
When you get a notification, compare the frame of the NSTextView or
NSTableView with the bounds of the scroll view's clip view (the
documentView frame and the clipView bounds are in the same coordinate
system) to determine whether the clip view is too big, too small or
just right.
If the clip view is the wrong size, you need to resize the view
containing the scroll view (so that the things adjacent to the scroll
view move out of its way) by the amount that the clip view is wrong.
Autoresizing should then trickle down and produce the results you want.
There are a few things to be careful of:
-- resizing view while you're in the notification handler method may
cause additional notifications, and you need to handle that
-- if you want the number of line/rows to change for other reasons
(e.g. when you resize the window), you might have to observe the clip
view frame too
-- if you have autohiding vertical scroll bars on you NSTextView or
NSTableView, you may end up in a situation where the scroll view size
change "bounces" up and down, and you need to handle that
HTH
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden