我试图在使用核心动画的NSView
中滑动。我认为我需要使用明确的动画,而不是依赖诸如[[view animator] setFrame:newFrame]
之类的东西。这主要是因为我需要设置动画委托才能在动画完成后采取行动。使用核心动画显式动画的NSView
我把它用动画师工作得很好,但正如我所说的,我需要在动画结束通知。我的代码目前的样子:
// Animate the controlView
NSRect viewRect = [controlView frame];
NSPoint startingPoint = viewRect.origin;
NSPoint endingPoint = startingPoint;
endingPoint.x += viewRect.size.width;
[[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
CABasicAnimation *controlPosAnim = [CABasicAnimation animationWithKeyPath:@"position"];
[controlPosAnim setFromValue:[NSValue valueWithPoint:startingPoint]];
[controlPosAnim setToValue:[NSValue valueWithPoint:endingPoint]];
[controlPosAnim setDelegate:self];
[[controlView layer] addAnimation:controlPosAnim forKey:@"controlViewPosition"];
这个视觉工作(和我在最后通知),但它看起来像实际controlView没有得到感动。如果我导致窗口刷新,controlView消失。我试着用
[controlView setFrame:newFrame];
更换
[[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
而且确实会导致视图(和层)移动,但它破坏的东西,使得我的应用程序与赛格故障去世不久。
最明确动画的例子似乎只能移动CALayer
。必须有办法移动NSView
并且也可以设置委托。任何帮助,将不胜感激。
感谢您的回复。我确实通过对代码进行了一些重新安排来完成这项工作。我认为苹果在WWDC期间的例子告诉你在设置动画之前操纵视图*。那么你如何使用动画师来使用代表?我已经搜索了很多关于这方面的例子,并且空着。我也看到许多帖子说这是不可能的。 – btschumy 2011-05-23 16:54:55
将代理设置为您的controlPosAnim,将其添加到controlView的动画中,将调用委托方法。 – 2011-05-24 22:36:58
好的感谢信息 – btschumy 2011-05-25 15:50:42