Synchronising views within an enclosing scroll view
Synchronising views within an enclosing scroll view
- Subject: Synchronising views within an enclosing scroll view
- From: Keith Blount <email@hidden>
- Date: Sun, 13 Feb 2005 07:46:08 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Hello,
I have two views within a single scroll view that I
need to keep in sync. One is a text view, and another
is a custom margin view used for keeping notes. To
keep them together, I can created an NSView subclass
and added the margin view and text view as subviews of
this, and I have set the NSView subclass as the
document view of the scroll view.
So far, so good. But setting it up so that the view
resizes itself properly so that it is always just the
right height to fit both the text view and the margin
view is giving me a real headache, and if anyone can
give me any advice on how to fix what I am doing, I
would be very grateful. Currently I am listening for
NSViewFrameDidChangeNotification in my custom NSView
subclass. Whenever this notification is posted, I try
to recalculate the size of the subviews using the
method posted below. The trouble is that sometimes it
doesn't change size, meaning that there is a lot of
white space beneath the text view, and sometimes it
changes size but is too small, so that some of the
text in the text view is cut off. If anyone can see
what I am doing wrong and point me in the right
direction, I would be very grateful.
The method:
// Make sure we can fit the subviews
-(void)updateSize:(NSNotification *)notification
{
id sender = [notification object];
NSClipView *clipView = [[self enclosingScrollView]
contentView];
// If the scroll view has changed size, or if one of
the notes
// in the margin view has changed size or moved, make
sure that
// the text view is big enough
if ( (sender == clipView) || ([sender
isKindOfClass:[HEMMarginCardView class]]) )
{
// Note that [marginView minHeight] returns the
minimum
// height needed to hold all of the marginal notes
float textHeight = MAX([marginView minHeight],[[self
enclosingScrollView] contentSize].height);
[textView setMinSize:NSMakeSize(0.0, textHeight)];
[textView sizeToFit];
}
// Now make sure margin and self (the document view
that contains
// the margin and text view as subviews) is just big
enough
// to hold everything
if (sender == textView)
{
float newHeight = [textView frame].size.height;
NSRect newFrame = [self frame];
newFrame.size.height = newHeight;
[self setFrame:newFrame];
newFrame = [marginView frame];
newFrame.size.height = newHeight;
[marginView setFrame:newFrame];
}
}
Many thanks in advance for any help,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden