触摸屏特有的NSScrubber控件在pan手势上以惯性滚动.我想被通知这个动画的结束,以执行一些功能。
尝试1
NSScrubberDelegate有一个- didFinishInteractingWithScrubber:方法,我实现了这个方法。然而,在我停止直接操作洗涤器后不久被选中的最后一项不是此委托方法被调用时的项。
尝试2
更进一步,我偶然发现了NSAnimation。虽然没有明确的文档,但我想洗涤器也是一个NSAnimatablePropertyContainer,因为它的selectedIndex属性文档说,您可以通过动画代理来动画选择,例如:scrubber.animator.selectedIndex = i。根据这个优点,假设平滑平移的动画属性是boundsOrigin,我试着查询它。
我通过这样做就能得到一个CAAnimation
CAAnimation* a = [NSScrubber defaultAnimationForKey:@"boundsOrigin"];
// returns the same pointer value as above
// a = [myScrubber animationForKey:@"boundsOrigin"];
a.delegate = self;
...
- (void)animationDidStop:(CAAnimation *)anim
finished:(BOOL)flag {
if (flag == YES)
NSLog(@"Animation ended!\n");
}我为a获得一个有效的指针值。但是,我收到了许多对animationDidStop flag = YES**;的调用,所有调用都是以flag = YES**;作为洗涤卷,我一直收到这些调用,而当滚动卷停止调用时,调用停止。这感觉很接近我想要的,但我不知道为什么在动画结束的时候会有这么多的电话出现,而不是一个。
由于NSScrubber的NSView或NSScrollView没有公开,所以我不确定是否在查询正确的对象以获得正确的NSAnimation。
尝试3
我也尝试了在操作端代码上做这件事的麻烦事,但没有成功。
-(void)didFinishInteractingWithScrubber:(NSScrubber *)scrubber {
NSLog(@"Manipulation ended\n");
NSAnimationContext*c = NSAnimationContext.currentContext;
[c setCompletionHandler:^{
NSLog(@"Inertial scrolling stopped!\n");
}];
}在惯性滚动停止之前,几乎立即调用完成处理程序:(
问
有没有人知道洗涤器的盘状惯性动画何时结束?
发布于 2019-03-30 18:54:33
我终于找到了一种方式,为pan手势的惯性滚动动画结束注册回调。
和任何其他滚动视图一样,这个视图也有NSScrollViewDidEndLiveScrollNotification。使用通知中心注册回调!
NSScrollView *sv = myScrubber.enclosingScrollView;
// register for NSScrollViewWillStartLiveScrollNotification if start is also needed
[[NSNotificationCenter defaultCenter] addObserverForName:NSScrollViewDidEndLiveScrollNotification
object:sv
queue:nil
usingBlock:^(NSNotification * _Nonnull note) {
NSLog(@"Scroll complete");
}];感谢这个答案展示了这种方法。
https://stackoverflow.com/questions/55264098
复制相似问题