Stop NSScrollView only on specific values - Like UIScrollView paging

谁说我不能喝 提交于 2019-12-04 23:09:19

You can use NSScrollViewDidEndLiveScrollNotification:

NSScrollView* scrollView;
const CGFloat interval = 100;
[[NSNotificationCenter defaultCenter]
 addObserverForName:NSScrollViewDidEndLiveScrollNotification
 object:scrollView
 queue:nil
 usingBlock:^(NSNotification* notification) {
     CGFloat offset = scrollView.contentView.bounds.origin.y;
     offset = round(offset / interval) * interval;
     [scrollView.contentView.animator setBoundsOrigin:NSMakePoint(0, offset)];
 }];

You can use NSAnimationContext to tune the duration and timing of the animation.


Note: According to the docs, this notification was introduced in 10.9, so it wouldn't have been an option for the 10.7 deployment target mentioned in the original question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!