• 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: NSScrollView scroll notifications?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSScrollView scroll notifications?


  • Subject: Re: NSScrollView scroll notifications?
  • From: Keith Renz <email@hidden>
  • Date: Mon, 1 Nov 2004 23:22:12 -0500

I have a custom view that's inside an NSScrollView. This custom view sets up subviews of its own, and the subviews have subviews of their own. The latter subviews set up mouse tracking rectangles. I've set things up so that if their frame changes, or if their superview's frame changes, then the tracking rectangle is reset.

But when the view is scrolled, the tracking rectangles stay the same. How do I let the subviews know when the enclosing scroll view has been scrolled? I need to update the tracking rectangles when this happens... I've already tried watching for frame-did-change and bounds-did-change notifications (and turning them on) for the clip view and scroll view; neither worked.

I auto-sync a custom view's position (outside a scroll view) to a table view's scrolled position using bounds changed notifications and it seems to work well. As you probably know, the only view which changes when you scroll is the clip view. So that's the view which needs to post the bounds changed notifications. You say you've turned on bounds changed notifications for the clip view. Did you do this with something like?


[[myTableView superview] setPostsBoundsChangedNotifications:YES];

I'm scrolling a table view which is in a nib, so I do this in my NSWindowController subclass's windowDidLoad method. If you're not subclassing NSWindowController, there are several other places you can do it.

Are you registering for bounds changed notifications?

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myTableClipBoundsChanged:) name:NSViewBoundsDidChangeNotification object:[myTableView superview]];

I do this in my NSWindowController subclass's init method.

The last part is in the notification selector method.

- (void)myTableClipBoundsChanged:(NSNotification *)notification
{
	NSRect newClipBounds = [[notification object] bounds];
}

The notification object is the view whose bounds has changed. In this case, the clip view. So, [[notification object] bounds] will give you the clip view's new bounds.

In my NSWindowController subclass's windowDidLoad method, I also save the clip view's initial bounds so I can compare it to the new bounds and see how far my table view has been scrolled. I then use the difference in positions to re-position my external view.

Keith

_______________________________________________
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


References: 
 >NSScrollView scroll notifications? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: drawRect - top to bottom text
  • Next by Date: Re: Header Files and Links to documentation
  • Previous by thread: NSScrollView scroll notifications?
  • Next by thread: [SOLVED] Re: NSScrollView scroll notifications?
  • Index(es):
    • Date
    • Thread