Re: NSScrollView refuses to scroll
Re: NSScrollView refuses to scroll
- Subject: Re: NSScrollView refuses to scroll
- From: "Kyle Sluder" <email@hidden>
- Date: Wed, 7 Jan 2009 22:23:58 -0500
On Wed, Jan 7, 2009 at 4:13 PM, Jason Cox <email@hidden> wrote:
> Am i just completely missing the concept of what NSScrollView does?????
Scroll views are a pretty complicated beast. A scroll view has a
document view, which is the thing being scrolled, and a clip view
which ensures that only the appropriate portion of the document view
is visible. It essentially accomplishes this by screwing around with
its own bounds and frame so that your document view still thinks it's
drawing as normal.
This hopefully makes it a bit more apparent why setting the document
view of a scroll view to autosize is a counterproductive idea. When
you set the document view to fill, the clip view will constantly
resize the document view's frame to be the same size as its own
bounds. This will in turn cause the clip view's bounds to be sized to
the same as its frame, which makes everything in the chain the same
size. Instead, you want the document view to set its frame to
whatever size is appropriate for the document, and not autosize. Then
the clip view will notice when the document view's frame is smaller
than its own bounds and inform the scroll view to display the
appropriate scrolling bars.
(Like I said, it's complicated. Just keep playing with scroll
views--take them apart in code or in IB--and make absolutely sure you
understand how frames, bounds, and resize notifications work.)
As for the NSTextView: when you drag an NSTextView out from the
Library, you're actually dragging out an NSScrollView that has a
document view which is an NSTextView. If you drag it inside of the
scroll view you now have the following view hierarchy:
NSScrollView
NSClipView
NSView
NSScrollView
NSClipView
NSTextView
You can probably understand why this isn't what you want. That NSView
in particular is the problem. When you drag the NSScrollView out of
the Library, its document view is just a plain old NSView, and you've
added the NSTextView as a subview of that view.
HTH,
--Kyle Sluder
_______________________________________________
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