Expanding NSScrollView
Hi All, I've dug around through the archives, but couldn't turn anything up that addresses this question, so I turn to the collective wisdom of the list. I'm trying to figure out how to create an NSScrollView subclass that expands vertically rather than scrolling, up to a certain height. For instance, a scrollview containing an NSTextView would expand itself when the textview exceeded the visible rect, until the textview reached a certain length, at which point normal scrolling behavior would commence. Likewise, it would shrink back along the same parameters. I am imagining that this might have something to do with the ClipView, but I may be way off. Alternatively a scrollViewShouldScroll: delegate method would be convenient at this point. If that wasn't coherent, or if anyone has any ideas, I would be sincerely grateful. Peace, Andy Shamel ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Expanding NSScrollView
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Expanding NSScrollView
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/mercator%40pileofdebris.com This email sent to merca...@pileofdebris.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Expanding NSScrollView
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com