Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Uncollapsing split view

Uncollapsing split view
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 1, 2004, 02:56 PM
 
Hi guys,

I have a split view that I can collapse using this code:

Code:
- (void)splitViewDoubleClick:(OASplitView *)sender { NSView *topView = [[sender subviews] objectAtIndex:0]; NSView *botView = [[sender subviews] objectAtIndex:1]; NSRect lastTopFrame = [topView frame]; NSRect lastBotFrame = [botView frame]; if(lastBotFrame.size.height==0) { // UnCollapse here. } else { lastTopFrame = [topView frame]; lastBotFrame = [botView frame]; lastBotFrame.size.height -= lastTopFrame.size.height; [topView setFrame: lastTopFrame]; lastBotFrame.size.height = 0; [botView setFrame: lastBotFrame]; [sender adjustSubviews]; } }
Doing this, when I double click the split view collapses. But, I am wondering how I would go about uncollapsing it? By uncollapsing I mean returning the split view back to its original size. Any idea how to get the size before it was double clicked?

Thanks,
Oliver
     
qyn
Dedicated MacNNer
Join Date: Dec 2000
Location: sj ca
Status: Offline
Reply With Quote
May 1, 2004, 04:35 PM
 
I think you just have to remember it yourself. In the collapse code, you'll have to store the
values lastTopFrame and lastBotFrame so you can retrieve them later. Cause otherwise they're gone forever.

Is anyone else annoyed that the code is turned into smileys?
     
Mac Elite
Join Date: Jan 2003
Location: NYC
Status: Offline
Reply With Quote
May 1, 2004, 05:04 PM
 
yeah, couldn't you just store lastBotFrame.size.height in a variable before you collapse it, and then when you uncollapse, just return it to that value. i've never actually tried to do this, but it seems like it should work.



edit: aren't the first two lines of the else statement redundant, because you already assign those values before the if statement?
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 1, 2004, 05:35 PM
 
Originally posted by MaxPower2k3:
edit: aren't the first two lines of the else statement redundant, because you already assign those values before the if statement?
Oops, I edited the code here, and forgot about the else bit . I'll try storing those values.

Thanks,
Oliver
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 2, 2004, 12:46 PM
 
For anyone that needs this code in the future, here it is (thanks smeger):

Code:
- (void)splitViewDoubleClick:(OASplitView *)sender; { NSView *topView=[[sender subviews] objectAtIndex:0]; NSView *botView=[[sender subviews] objectAtIndex:1]; NSRect topFrame=[topView frame]; NSRect botFrame=[botView frame]; if( 0 == botFrame.size.height ) { // Uncollpase split view here. [topView setFrame: mLastTopFrame]; [botView setFrame: mLastBotFrame]; [sender adjustSubviews]; } else { // Collapse split view. mLastTopFrame = topFrame; mLastBotFrame = botFrame; NSRect splitViewFrame = [sender bounds]; [topView setFrame: NSMakeRect(0, 0, splitViewFrame.size.width, splitViewFrame.size.height - [sender dividerThickness])]; [botView setFrame: NSZeroRect]; [sender adjustSubviews]; } }
In your header (.h) file, define both mLastTopFrame and mLastBotFrame as NSRect's. so NSRect mLastTopFrame; and NSRect mLastBotFrame;

Thanks,
Oliver
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
May 2, 2004, 07:42 PM
 
Originally posted by qyn:
Is anyone else annoyed that the code is turned into smileys?
That's what the disable smilies button is for :) :D :p ;)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:28 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2