Re: Cannot get hidden NSTextView to show (SOLVED)
Re: Cannot get hidden NSTextView to show (SOLVED)
- Subject: Re: Cannot get hidden NSTextView to show (SOLVED)
- From: Sam Stigler <email@hidden>
- Date: Wed, 23 May 2007 23:45:29 +1000
Hi Aaron,
Thanks for that "pimp." It really did make the code look a lot
cleaner; a lot easier to read. The one weird thing that was
happening was that whenever I would hide the expanded view (i.e., the
disclosure button was in its off state), the entire window would
slide to the bottom of where the expanded view had been. I finally
figured out that I had to change the line: windowFrame.origin.y -=
boxHeight to a +=. I still really do not completely understand why;
all I know is that for some reason it worked.
Sam
On May 20, 2007, at 1:07 PM, Aaron Burghardt wrote:
Hi Sam,
Glad you got it figured out. May I offer some suggestions in the
spirit of Wil Shipley's "Pimp my code"?
First, read NSView's setHidden: documentation: all subviews of a
hidden view are also hidden. So, when you hide the text view's scroll
view, the text view will also be hidden, taking the burden off you to
do so.
But, you can take that a step further. Group the text view and your
button inside a box view (it's an option in IB's menus). You can
hide the title and border of the box so that it is invisible (but not
hidden!). Create a outlet to the box (assume it is named myBox for
my example below). This allows two things: one, you can hide/show
all the controls by calling setHidden on the box. Two, you can use
the box frame to get rid of the hard-coded heightDifference. Thus,
your method reduces to:
- (IBAction)toggleTextPreviewView:(id)sender
{
NSRect windowFrame = [mainWindow frame];
float boxHeight = NSHeight( [myBox frame] );
if ( [sender state] == NSOnState )
{
windowFrame.origin.y += boxHeight;
windowFrame.size.height += boxHeight;
[mainWindow setFrame: windowFrame display:YES animate:YES];
[myBox setHidden: NO];
}
else
{
[myBox setHidden: YES];
windowFrame.origin.y -= boxHeight;
windowFrame.size.height -= boxHeight;
[mainWindow setFrame: windowFrame display:YES animate:YES];
}
}
This assumes you aren't really using oldFrame outside of this
method. Written in Mail, so usual disclaimer applies.
Cheers,
Aaron
On May 19, 2007, at 1:58 PM, Sam Stigler wrote:
Just answered my own question right after I posted this; it turns out
I also have to hide and show the text view's scroll view as well.
Sam
On May 20, 2007, at 3:50 AM, Sam Stigler wrote:
[deleted for the sake of not having this message rejected from the
list for its size.]
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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