如何确定NSScrollView当前是否正在滚动

ica*_*ant 6 macos cocoa nsscrollview

如何确定我的NSScrollView当前是否正在滚动?在iOS上,我可以使用委托,但尽管谷歌搜索很多,我无法在Mac上找到这样的方法.

提前致谢!

daf*_*afi 13

您可以收到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];
Run Code Online (Sandbox Code Playgroud)

通知方法

- (void)boundDidChange:(NSNotification *)notification {
    // get the changed content view from the notification
    NSClipView *changedContentView=[notification object];
}
Run Code Online (Sandbox Code Playgroud)


Tom*_*ing 6

从OS X 10.9开始也有NSScrollView.willStartLiveScrollNotification.它在用户滚动事件开始时发布在主线程上.

例如

NotificationCenter.default.addObserver(self, selector: #selector(scrollViewDidScroll), name: NSScrollView.willStartLiveScrollNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)