Based similar questions asked about UIView and UITextField shake animations, Ive implemented this code which should apply to NSTextFields. However the animation never runs. What is the problem here?
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"];
Note: [[textfield animator] setFrameOrigin:one];
successfully moves the textfield