7

NSScrollViewが現在スクロールしているかどうかを確認するにはどうすればよいですか?iOSではデリゲートを使用できますが、グーグルをたくさん使用しているにもかかわらず、Macでこれを行う方法を見つけることができません。

前もって感謝します!

4

3 に答える 3

14

以下に示すような通知NSViewBoundsDidChangeNotificationを受け取ることができます

NSView *contentView = [scrollview contentView];

[contentView setPostsBoundsChangedNotifications:YES];

// a register for those notifications on the content view.
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(boundDidChange:)
                                             name:NSViewBoundsDidChangeNotification
                                           object:contentView];

通知方法

- (void)boundDidChange:(NSNotification *)notification {
    // get the changed content view from the notification
    NSClipView *changedContentView=[notification object];
}
于 2012-12-16T16:02:31.787 に答える
7

OS X 10.9の時点で、もありNSScrollView.willStartLiveScrollNotificationます。これは、ユーザースクロールイベントの開始時にメインスレッドに投稿されます。

例えば

NotificationCenter.default.addObserver(self, selector: #selector(scrollViewDidScroll), name: NSScrollView.willStartLiveScrollNotification, object: nil)
于 2016-05-19T17:22:57.467 に答える
2

OSX mojave /swift5の私の2セント

 let nc =  NotificationCenter.default

    nc.addObserver(
        self,
        selector: #selector(scrollViewWillStartLiveScroll(notification:)),
        name: NSScrollView.willStartLiveScrollNotification,
        object: scrollView
    )

    nc.addObserver(
        self,
        selector: #selector(scrollViewDidEndLiveScroll(notification:)),
        name: NSScrollView.didEndLiveScrollNotification,
        object: scrollView
    )

...。

   @objc func scrollViewWillStartLiveScroll(notification: Notification){
        #if DEBUG
        print("\(#function) ")
        #endif
    }


    @objc func scrollViewDidEndLiveScroll(notification: Notification){
        #if DEBUG
        print("\(#function) ")
        #endif
    }
于 2019-04-10T07:20:51.233 に答える