NSView, NSScrollView, NSClipView: IMReallyImpressed

I’ve just started working on the graphics part of my program and thus far I’ve been massively impressed by Cocoa’s offerings in this area. Admittedly, I haven’t done a whole lot — I’m currently just drawing using NSString’s drawInRect:withAttributes: (from AppKit’s NSString additions) and some NSBezierPath methods.

The largest source of awe so far has been just how easy it is to place an NSView subclass inside an NSScrollView. This is a task that involves no code whatsoever — one simply has to select the “Make subviews of > Scrollview” command in Interface Builder and your custom view is now scrollable.

I think the most impressive facet of this set up is the elegance of the view hierarchy. Your custom NSView subclass effectively forms a canvas, only a portion of which is displayed in the scroll view. The visible part of the view is generally referred to as the content view (and is an instance of NSClipView) and that’s pretty much it — the scroll view provides the scroll bars and resizes them as the size of the “canvas” changes (I’m using NSView’s setFrameSize: and setFrameOrigin: methods to obtain the desired stretching of my view in response to an NSSlider.) Here’s how it’s looking at the moment:

GFF Viewer window

Leave a Reply

Your email address will not be published. Required fields are marked *