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 / swift 5 两分钱

 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 回答