Re: Expanding NSScrollView
Re: Expanding NSScrollView
- Subject: Re: Expanding NSScrollView
- From: Andrew Shamel <email@hidden>
- Date: Tue, 21 Jul 2009 12:55:56 -0700
Thanks for the quick response!
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)
Where I am having trouble is in figuring out how to implement the
behavior reliably when the CardView is automatically resized, for
instance, as the window is resized. I was hoping therefore, to figure
out a more generalized method of getting the scrollview or some
delegate to do it automatically, observing the size of its content as
the content is resized, and resizing the content as it is resized by
its superview.
As an example:
given:
CardView *card // assigned elsewhere
NSScrollView *scroller //assigned elsewhere
[card addSubview:scroller];
NSTextView *textView = [scroller documentView];
Say textView has a sentence of text in it that fits on one line when
card is at a given width. In textView, I add another sentence,
expanding to two lines of text. At this point, scroller should get
taller to accommodate the text. When card shrinks as the window
shrinks horizontally, scroller is resized as per its autosizing
settings. As card and scroller get narrower, what had once fit on two
line is now forced onto three. Normally, this would activate the
scrollbars and all kinds of scrolling joy would commence. I want to
be able to control its vertical expansion relative to the needs of the
text inside it. As the views narrow, rather than expanding wantonly
as they might with autosizing settings, I want to retain the fine
control I have when new text is entered, so as to control when and how
it grows and/or applies scrolling behavior.
Whew! I hope that's clearer.
Thanks again for your help.
— a
On 21 Jul 2009, at 12:12 PM, Quincey Morris wrote:
On Jul 21, 2009, at 11:55, Andrew Shamel wrote:
I'm trying to figure out how to create an NSScrollView subclass
that expands vertically rather than scrolling, up to a certain
height.
Expands vertically when what? When the window is resized? Or is it
supposed to resize its window when it wants to expand?
Expands vertically into what? Are there other elements around it
that have to be moved out of the way? Is it the sole content of the
window?
If you can answer those questions, you'll know what to do with the
scroll view.
_______________________________________________
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
_______________________________________________
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