6

I have a CAEmitterLayer animated along a bezier path (closed form, like an '8', out of four control points) with a CAKeyframeAnimation. Now I want to control the animation by a slide of a touch-finger along (but not necessarily on) the path. How is this possible and is this even possible?

4

1 回答 1

1

创建一个CGpoint click;变量来记住您的初始“拖动”点,然后创建一个本地NSEvent处理程序......

[NSEvent addLocalMonitorForEventsMatchingMask: NSMouseMovedMask
                                             | NSLeftMouseDownMask 
                                      handler:^(NSEvent *e) {
    if ( e.type == NSLeftMouseDown ) click = e.locationInWindow;
    else "yourDelta" = click - e.locationInWindow;  // pseudoCode 
    return e;
}];

“yourDelta”是该初始点与当前位置的偏移量...您还可以通过监视NSEventScrollWheelMask...并查看e.deltaXande.deltaY值来通过滚动事件获得类似的结果。

编辑:我对iOS上的事件处理不太熟悉。但同样的技术可以应用于普通的事件处理程序......即。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)e {
    click = [e locationInView:_yourView];       
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)e {
    "yourDelta" = click - [e locationInView:_yourView];  // pseudoCode 
}

至于“寻找”你的动画。一种可能的方法是简单地[layer addAnimation:theNewAnimation]使用你以前toValue的 's,而不是基于fromValue0 的's,或者你的模型layer......改用你的layer.presentationLayer值?没有看到你的全部内容很难说CAKeyframeAnimation

于 2012-11-20T15:45:37.867 回答