Re: example of a NSScrollView where scrolling is overridden ?
Re: example of a NSScrollView where scrolling is overridden ?
- Subject: Re: example of a NSScrollView where scrolling is overridden ?
- From: James Bucanek <email@hidden>
- Date: Sun, 30 May 2010 07:42:27 -0700
Guillaume Laurent <mailto:email@hidden> wrote
(Sunday, May 30, 2010 2:59 AM +0200):
I need to scroll over a potentially very large area, that area has CALayers,
which will themselves "be" very large. That is, they will appear so. So I need
to have control over the scrolling so that those "large" CALayers will appear
to scroll but actually redrawing their content as appropriate.
From what I gather, I need to override NSScrollView:drawRect and from that to
somehow drive the drawing in the underlying NSView, but I'd like to see a
working example or something similar, if anybody has some.
I think you might be approaching this with a greater degree of
difficulty than is necessary.
An NSScrollView presents, clips, and scrolls around a subset of
a subview. The subview does the drawing of the content, not
NSScrollView, so overriding -[NSScrollView drawRect:] isn't
appropriate. The point being that NSScrollView already does
exactly what your talking about doing, so I'm not sure why you
need to reinvent it.
It seems to me that your choices should be (in order of preference)
(1) Override the -drawRect: of your NSView, or the
-drawInContext: of your CALayer. Both of these calls will be
passed the exact rectangle to be drawn, which will (by
definition) be contained within the currently visible area
within the scroll view. Draw *just* what's inside the draw Rect
or clipping bounds and Bob's your uncle. In fact, your
NSView/CALayer should be doing that already, but if it isn't
fixing that should complete your solution.
(2) Write your own custom NSView to slides around a big CALayer,
clipped to the NSView's bounds, essentially rolling your own NSScrollView.
The first choice would be good if you want all of the goodies
(scrollbars, delegate events, ...) that come with NSScrollView
for free. The second would be the best if you really don't want
all of the NSScrollView stuff except the subview clipping bit.
--
James Bucanek
_______________________________________________
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