UIView と UITextField のシェイク アニメーションに関する同様の質問に基づいて、NSTextField に適用する必要があるこのコードを実装しました。ただし、アニメーションは実行されません。ここで何が問題なのですか?
NSRect textFieldFrame = [textfield frame];
CGFloat centerX = textFieldFrame.origin.x;
CGFloat centerY = textFieldFrame.origin.y;
CABasicAnimation *animation = [[CABasicAnimation alloc] init];
animation.keyPath = @"position";
animation.duration = 0.07;
animation.repeatCount = 4;
animation.autoreverses = true;
NSPoint one = NSMakePoint(centerX-5, centerY);
NSPoint two = NSMakePoint(centerX+5, centerY);
animation.fromValue = [NSValue valueWithPoint:one];
animation.toValue = [NSValue valueWithPoint:two];
[textfield.layer addAnimation:animation forKey:@"position"];
注:[[textfield animator] setFrameOrigin:one];
テキストフィールドを正常に移動します