您可以简单地使用动画师为 NSTextField 的位置设置动画,例如
[[textField animator] setFrameOrigin:NSMakePoint(x,y)];
你也可以像这样将它嵌入到“CATrancation”代码中:
[CATransaction begin];
[CATransaction setAnimationDuration:0.5];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[[textField animator] setFrameOrigin:NSMakePoint(x,y)];
[CATransaction commit];
如果你需要动画委托,你可以使用 CABasicAnimation
CABasicAnimation* animation = [CABasicAnimation animation];
animation.delegate = self;
NSDictionary *animations = [NSDictionary dictionaryWithObjectsAndKeys:animation,@"frameOrigin",nil];
[textField setAnimations:animations];
[[textField animator] setFrameOrigin:NSMakePoint(x,y)];
委托方法是
- (void)animationDidStart:(CAAnimation *)theAnimation;
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag;
如果您需要屏蔽您的文本字段,只需将其嵌入到其他 NSView 中。