Custom view resizing
Custom view resizing
- Subject: Custom view resizing
- From: Robert Olivier <email@hidden>
- Date: Thu, 28 May 2009 17:14:21 -0700
I'm a new Cocoa programmer working on my first non-trivial custom view
and I have a question regarding the right way to handle view resizing.
Say that I have a list of shapes that I need to draw left to right
across my view, and this list grows over time. Eventually, I will
need to draw a shape outside of the existing view frame and I when
this happens I want to resize the view.
Initially I had all of the drawing code directly in the view and when
the code detected that the next shape would be outside of the existing
view bounds it would resize it like this:
if((current + spacing + headerSize.width) >= rect.size.width) {
NSSize newSize;
newSize.width = [self frame].size.width + spacing+headerSize.width;
newSize.height = [self frame].size.height;
[super setFrameSize:newSize];
[self setNeedsDisplay:YES];
}
I want to move to a model where the shapes draw themselves rather than
having all of the drawing code in the custom view, but without the
shape object knowing anything about the NSView object itself, only the
NSRect that is being drawn.
What is the best practice for this? Am I thinking right that the
shapes should draw themselves rather inspecting each shape and drawing
it in the view? IF so, and a shape object knows that the view is not
big enough for it to render itself, should it send a notification to
the view telling it to resize or would it be best to just let the
shape objects know about the NSView object? What are the implications
for pagination during a print job?
I've looked at all the book examples that I have and did some
searching on view resizing but none of the examples seem to really
cover this case.
Thanks in advance for any help!
rjo
_______________________________________________
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