2011-03-02 71 views
32

我正在做的Mac應用程序,它需要知道當用戶滾動NSScrollView,但是,我無法找到像UIScrollView,它具有以下的委託方法的任何方法:NSScrollView滾動時的回調?

– scrollViewDidScroll: 
– scrollViewWillBeginDragging: 
– scrollViewDidEndDragging:willDecelerate: 
– scrollViewShouldScrollToTop: 
– scrollViewDidScrollToTop: 
– scrollViewWillBeginDecelerating: 
– scrollViewDidEndDecelerating: 

我能有App Kit的類似委託方法?提前致謝。

啓。

回答

60

您可以通過監視其內容視圖的界限來監視滾動視圖的更改。首先設置內容視圖與

[contentView setPostsBoundsChangedNotifications:YES]; 

發佈其變化那麼作爲這些通知的觀察者與

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChange:) name:NSViewBoundsDidChangeNotification object:contentView]; 
3

註冊有同樣的問題最近...要有點模仿減速回調有可能覆蓋

-(void) scrollWheel:(NSEvent *)theEvent 
NSScrollView類

,但隨後檢查theEvent.momentumPhase,而不是theEv事件階段的ent.phase。