Re: Synchronising views within an enclosing scroll view
Re: Synchronising views within an enclosing scroll view
- Subject: Re: Synchronising views within an enclosing scroll view
- From: Keith Blount <email@hidden>
- Date: Mon, 14 Feb 2005 11:36:20 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks for your reply - much appreciated.
Unfortunately, I cannot implement this code in
resizeSubviewsWithOldSize: because it works in the
inverse way to that - instead of the view resizing its
subviews as in that method, the view needs to resize
to fit its subviews when *they* change size (for
instance, when the text view expands to fit more text
that is typed or is resized horizontally and therefore
changes vertically). As the text view has only its
NSViewWidthSizable flag set and the margin view is has
no sizable flags set, this shouldn't be a problem.
As far as I can see, the only way to do this is by
listening for changes in the sizes of the subviews and
resizing the superview to fit them perfectly - which
is what I am trying to do in the method posted below,
but so far with a number of large glitches.
If anyone has any more suggestions I would be very
grateful.
Many thanks again for the help,
Keith
--- daniel <email@hidden> wrote:
> 1. Since you're subclassing an NSView, maybe you
> should implement this
> functionality within its resizeSubviewsWithOldSize.
> I haven't looked
> too carefully at the code below, but it looks like
> you're trying to be
> a little too omnipotent, paying attention to other
> views changing size
> when you should just pay attention to your own
> custom view changing.
>
> 2. When you change the frame of a view you need to
> let it know that it
> needs to redraw itself (setNeedsDisplay).
>
> Hope this helps get you further along.
>
> Daniel
>
> On Feb 13, 2005, at 7:46 AM, Keith Blount wrote:
>
> > 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:
> >
>
>
> > sweater.com
> >
> > This email sent to email@hidden
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250
_______________________________________________
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