有时候你可能需要在用户滚动NSScrollView的时候获得通知,以便进行更多自定义的处理。本文的方法可以帮助你获得这些通知。 如果你希望在滚动视图滚动时获取通知,你需要先告诉 c
有时候你可能需要在用户滚动NSScrollView的时候获得通知,以便进行更多自定义的处理。本文的方法可以帮助你获得这些通知。
如果你希望在滚动视图滚动时获取通知,你需要先告诉
contentView
在边框改变时发送通知,然后接收
NSViewBoundsDidChangeNotification:
[[scrollView contentView] setPostsBoundsChangedNotifications: YES];
NSNotificationCenter *center = [NSNotificationCenter defaultCenter] ;
[center addObserver: self
selector: @selector(boundsDidChangeNotification:)
name: NSViewBoundsDidChangeNotification
object: [scrollView contentView]];
…
- (void) boundsDidChangeNotification: (NSNotification *) notification
{
[self setNeedsDisplay: YES];
//
在这里进行处理
} // boundsDidChangeNotification