Callbacks When an NSScrollView is Scrolled?

问:

I'm making a Mac app which needs to know when the user is scrolling the NSScrollView, however, I can't find any methods like UIScrollView, which has the following delegate methods:

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

Can I have the similar delegate methods for the App Kit? Thanks in advance.


答:

You can monitor a scroll view's changes by monitoring the bounds of it's content view. First set the content view to post its changes with

[contentView setPostsBoundsChangedNotifications:YES];

Then register as an observer of those notifications with

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(boundsDidChange:) name:NSViewBoundsDidChangeNotification object:contentView]; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值