Guillaume Laurent <mailto:glaur...@telegraph-road.org> 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 (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

Reply via email to