• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Synchronising views within an enclosing scroll view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Synchronising views within an enclosing scroll view


  • Subject: Re: Synchronising views within an enclosing scroll view
  • From: daniel <email@hidden>
  • Date: Sun, 13 Feb 2005 19:06:36 -0800

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 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
  • Follow-Ups:
    • Re: Synchronising views within an enclosing scroll view
      • From: Keith Blount <email@hidden>
References: 
 >Synchronising views within an enclosing scroll view (From: Keith Blount <email@hidden>)

  • Prev by Date: Date Formatter fun
  • Next by Date: Re: Class design question
  • Previous by thread: Synchronising views within an enclosing scroll view
  • Next by thread: Re: Synchronising views within an enclosing scroll view
  • Index(es):
    • Date
    • Thread