所以我有一个名为* IBOutlet的口令,当用户输入错误的密码时,我调用了一个带有动画的方法:
- (void)shakeWithStrength:(NSInteger)strength {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [NSValue valueWithPoint:CGPointMake(password.frame.origin.x-strength, password.frame.origin.y)];
animation.toValue = [NSValue valueWithPoint:CGPointMake(password.frame.origin.x+strength, password.frame.origin.y)];
[password.layer addAnimation:animation forKey:@"position"];
}
我想把这个方法移到它自己的独立类中,但是我怎么能把NSSecureTextField (或者其他东西,比如一个按钮)作为参数来传递呢?
发布于 2018-05-31 18:16:43
NSView是NSSecureTextField,NSButton,NSTextField的超类。因此您可以使用NSView作为参数
- (void)shakeWithStrength:(NSInteger)strength view:(NSView *)view {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [NSValue valueWithPoint:CGPointMake(view.frame.origin.x-strength, view.frame.origin.y)];
animation.toValue = [NSValue valueWithPoint:CGPointMake(view.frame.origin.x+strength, view.frame.origin.y)];
[secureTextField.layer addAnimation:animation forKey:@"position"];
}
https://stackoverflow.com/questions/50621473
复制相似问题