Re: NSSplitview. Stopping the split moving
Re: NSSplitview. Stopping the split moving
- Subject: Re: NSSplitview. Stopping the split moving
- From: Markus Spoettl <email@hidden>
- Date: Sat, 14 Jun 2008 16:31:47 -0700
On Jun 14, 2008, at 4:15 PM, Steven Hamilton wrote:
I have an NSplitview similar to Mails. I'm trying to fix the split
so it doesn't move just like Mail but can't for the life of me
figure out how to do it. My left split has an Outlineview and the
right split a tableview. Resizing the window always moves the split
upsetting the visual appearance of the sourcelist in the left split.
You can do this by implementing the resizeSubviewsWithOldSize delegate
method, here is what I do. I have 2 views left is flexible in width,
right has fixed width.
- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:
(NSSize)oldSize
{
NSRect newFrame = [sender frame];
CGFloat dt = [sender dividerThickness];
// this is the fixed view (right)
// on top on being fixed it is also collapsible
NSRect rightFrame = [rightView frame];
// this is the flexible view (left)
NSRect leftFrame = [leftView frame];
rightFrame.size.height = newFrame.size.height;
leftFrame.size.height = newFrame.size.height;
if (![splitView isSubviewCollapsed:rightView]) {
rightFrame.origin.x = newFrame.size.width -
rightFrame.size.width;
rightFrame.origin.y = 0;
leftFrame.origin = NSMakePoint(0,0);
leftFrame.size.width = newFrame.size.width -
rightFrame.size.width - dt;
} else {
rightFrame.origin.x = newFrame.size.width;
rightFrame.origin.y = 0;
rightFrame.size.width = 0;
leftFrame.origin = NSMakePoint(0,0);
leftFrame.size.width = newFrame.size.width - dt;
}
[leftView setFrame: leftFrame];
[rightView setFrame:rightFrame];
}
The code above is a little modified from what I actually use and I
didn't compile it so it might need change. Also it can be condensed
considerably. Also note that you may need to implement
canCollapseSubview, constrainMaxCoordinate and constrainMinCoordinate
depending on what exactly you're trying to achieve.
The main disadvantage when doing this (as far as I can see) is that
you're responsible for correctly setting up all the child view frames.
The split view prints debug logs when you do something that is
completely wrong, so that helps.
Regards
Markus
--
__________________________________________
Markus Spoettl
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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