layout subviews
layout subviews
- Subject: layout subviews
- From: Torsten Curdt <email@hidden>
- Date: Wed, 25 Nov 2009 23:16:21 +0100
I have a flipped custom view (within a scroll view) which layouts it's
subviews as follows:
WORKS:
- (void) layoutSubviews
{
NSLog(@"layout");
NSRect frame = [self frame];
CGFloat width = frame.size.width;
CGFloat height = 0;
for(NSView *itemView in itemViews) {
height += [itemView frame].size.height;
}
NSLog(@"view height: %1.0f", height);
if (frame.size.height != height) {
frame.size.height = height;
[self setFrame:frame];
NSLog(@" - view: %@", NSStringFromRect(frame));
}
CGFloat y = 0;
for(NSView *itemView in itemViews) {
NSRect itemFrame = [itemView frame];
itemFrame.origin.y = y;
itemFrame.size.width = width;
[itemView setFrame:itemFrame];
NSLog(@" - item: %@", NSStringFromRect(itemFrame));
y += itemFrame.size.height;
}
[self setNeedsDisplayInRect:frame];
}
The above works just fine. What I don't understand is why moving the
adjustment of the frame size *after* the subview layout is breaking
it. By breaking I mean that some subviews are disappearing. It does
not seem to be a redraw/needsDisplay problem though. Rather like they
end up somewhere off screen.
DOESN'T WORK:
- (void) layoutSubviews
{
NSLog(@"layout");
NSRect frame = [self frame];
CGFloat width = frame.size.width;
CGFloat height = 0;
for(NSView *itemView in itemViews) {
height += [itemView frame].size.height;
}
CGFloat y = 0;
for(NSView *itemView in itemViews) {
NSRect itemFrame = [itemView frame];
itemFrame.origin.y = y;
itemFrame.size.width = width;
[itemView setFrame:itemFrame];
NSLog(@" - item: %@", NSStringFromRect(itemFrame));
y += itemFrame.size.height;
}
NSLog(@"view height: %1.0f", height);
if (frame.size.height != height) {
frame.size.height = height;
[self setFrame:frame];
NSLog(@" - view: %@", NSStringFromRect(frame));
}
[self setNeedsDisplayInRect:frame];
}
Anyone spotting a problem that I am missing?
cheers
--
Torsten
_______________________________________________
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