Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HerQ

macrumors newbie
Original poster
Jun 11, 2008
26
7
The Netherlands
Well, I want to implement some Collapsible NSBox'es which will be able to stack up vertically, without margin. I have been watching the Reducer.app sample code, and it's actually the thing I'd like to have.

My Collapsible Box class is working properly. It resizes the frame using NSAnimation nicely but there the problem begins: I have some more Collapsible NSBox'es below the perticular Collapsible NSBox, and I want them to stay just below the perticular NSBox, without margin. Now it just stays where I initially set it's frame origin to, which is not quite right because the NSBox above it became less in height.

Since Leopard doesn't support palettes anymore, I can't open the Reducer's .nib file. I can't really get into the way Apple did do this and I've been searching for quite a long time now, but nothing found yet.

I think it's possible to do this without an additional amount of code, since I can't find any of this this in Apple's example.

Thanks in Advance! Some images to make it more clear:

48fe5f1a55225-Good.png

All Opened: Good

48fe5f4bc9c43-Problem.png

Some Collapsed: Problem, the 'End Date' box needs to be below the 'Start Date' box, without margin.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you're not using NSViewAnimation you should be as this simplifies animating views (it's a subclass of NSAnimation). I think all you need to do is move the boxes below up via their frame.origin.y value by the height of the first box. You can do this all simultaneously with NSViewAnimation.
 

HerQ

macrumors newbie
Original poster
Jun 11, 2008
26
7
The Netherlands
Thanks for your reply.

I was already using the NSViewAnimation class, but you pointed me in the right direction:

Code:
id box;
NSMutableArray *animationArray = [NSMutableArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:self, NSViewAnimationTargetKey, [NSValue valueWithRect:newFrame], NSViewAnimationEndFrameKey, nil]];
NSEnumerator *iterator = [[[self superview] subviews] objectEnumerator];
float yOffset = COLLAPSED_HEIGHT == newFrameHeight ? previousHeight - COLLAPSED_HEIGHT : -newFrameHeight + COLLAPSED_HEIGHT;
BOOL flipped = [[self superview] isFlipped];
while(box = [iterator nextObject]) {
	NSRect frame = [box frame];
	if(box != self && [box isKindOfClass:[NSBox class]] && ((flipped && frame.origin.y > [self frame].origin.y) || (!flipped && frame.origin.y < [self frame].origin.y))) {
		frame.origin.y += flipped ? -yOffset : yOffset;
		[animationArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:box, NSViewAnimationTargetKey, [NSValue valueWithRect:frame], NSViewAnimationEndFrameKey, nil]];
	}
}
This works beautifully, but I still think it's possible without any code. But whatever, this works great!

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.