How to observe NSScroller changes?

后端 未结 1 1170
温柔的废话
温柔的废话 2021-01-13 19:42

I have an NSScrollView subclass and I would like to update another NSView based on the current scroll position. I tried KVC-observing the val

相关标签:
1条回答
  • 2021-01-13 20:32

    Tell the scroll view's content view to post bounds changed notifications, then listen for NSViewBoundsDidChangeNotification.

    [[aScrollView contentView] setPostsBoundsChangedNotifications:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(boundsDidChangeNotification:)
                                                 name:NSViewBoundsDidChangeNotification
                                               object:[scrollView contentView]];
    

    As stated in the Scroll View Programming Guide, you can get the current scroll position this way:

    NSPoint currentScrollPosition = [[theScrollView contentView] bounds].origin;
    
    0 讨论(0)
提交回复
热议问题