44

ユーザーがいつスクロールしているかを知る必要があるMacアプリを作成していますが、次のデリゲートメソッドを持つのNSScrollViewようなメソッドが見つかりません。UIScrollView

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

App Kitに同様のデリゲートメソッドを使用できますか?前もって感謝します。

カイ。

4

5 に答える 5

77

コンテンツビューの境界を監視することにより、スクロールビューの変更を監視できます。まず、変更を投稿するようにコンテンツビューを設定します

[contentView setPostsBoundsChangedNotifications:YES];

次に、これらの通知のオブザーバーとして登録します。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChange:) name:NSViewBoundsDidChangeNotification object:contentView]; 
于 2011-03-02T15:34:29.567 に答える
6

Swift 4のアップデート:

scrollView.contentView.postsBoundsChangedNotifications

また、呼び出しは次のとおりです。

NotificationCenter.default.addObserver(self,
                                       selector: #selector(boundsChange),
                                       name: NSView.boundsDidChangeNotification,
                                       object: scrollView.contentView)

編集:macのコレクションはscrollviewから継承しません。適切に更新されました

于 2018-03-22T22:14:13.303 に答える
4

最近同じ問題が発生しました...減速コールバックをいくらかエミュレートするために、オーバーライドすることが可能です

-(void) scrollWheel:(NSEvent *)theEvent 

NSScrollViewクラスのですが、イベントフェーズについては、 event.phaseではなくtheEvent.momentumPhaseを確認してください。

于 2012-12-12T08:04:44.210 に答える
4

@SeanRichの回答に追加します。

contentViewとのNSClipViewNSScrollViewですNSCollectionView

ストーリーボードからのクリップビューの画像

これを機能させるには、通知オブジェクトClipViewに設定する必要がpostsBoundsChangedNotifications あり、通知オブジェクトに渡す必要があります。

self.clipView.postsBoundsChangedNotifications = true

NotificationCenter.default.addObserver(self,
                                       selector: #selector(collectionViewDidScroll(notification:)),
                                       name: NSView.boundsDidChangeNotification,
                                       object: self.clipView)
于 2018-05-06T03:45:20.377 に答える
0

迅速な4.2OSXの私の2セント:

...。

if let clipView = self.collectionView.superview, let sv = clipView.superview as? NSScrollView{

        let contentView = sv.contentView
        contentView.postsBoundsChangedNotifications = true

        NotificationCenter.default.addObserver(self,
                                               selector: #selector(collectionViewDidScroll(notification:)),
                                               name: NSView.boundsDidChangeNotification,
                                               object: clipView)
}








 //MARK: scrollview observer:

    @objc func collectionViewDidScroll(notification: Notification){

    }
于 2019-03-26T10:28:22.827 に答える