Greetings,
I am writing an NSView subclass which will automatically arrange other NSViews that are added to it via the addSubview method. To wit, I've written the following code:
- (void) didAddSubview:(NSView *)view { unsigned driveCount; NSRect viewFrame; float verticalPadding = 0.0f; NSRect myFrame; float boundsHeight;
driveCount = [[self subviews] count] - 1; viewFrame = [view frame]; viewFrame.origin.y = (viewFrame.size.height + verticalPadding) * driveCount; [view setFrame: viewFrame];
boundsHeight = (viewFrame.size.height + verticalPadding) * (driveCount + 1); myFrame = [self frame]; myFrame.size.width = viewFrame.size.width; myFrame.size.height = boundsHeight;
// Resize our JukeBox view [self setBounds:NSMakeRect(0, 0, myFrame.size.width, myFrame.size.height)]; [self setFrame:myFrame]; }
(This method is called by the addSubview method, as stated in the NSView class documentation.)
In my document class, I add several views to this NSView-subclassed view, and I have added this very class (through IB) to my document's window with a very small size (2 pixels by 4 pixels). I would think that the setBounds and setFrame methods would properly resize the NSView in my document window, but alas, the resulting view is showing up as a 2x4 pixel area on my window.
I would have thought that setBounds and setFrame are sufficient to get a view to resize, so Is there something else I should be doing? Is "didAddSubview" the wrong place to perform this type of operation?
Boisy
|