首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >将NSTextFiels作为方法参数传递?

将NSTextFiels作为方法参数传递?
EN

Stack Overflow用户
提问于 2018-05-31 17:53:17
回答 1查看 28关注 0票数 0

所以我有一个名为* IBOutlet的口令,当用户输入错误的密码时,我调用了一个带有动画的方法:

代码语言:javascript
复制
- (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 (或者其他东西,比如一个按钮)作为参数来传递呢?

EN

回答 1

Stack Overflow用户

发布于 2018-05-31 18:16:43

NSView是NSSecureTextField,NSButton,NSTextField的超类。因此您可以使用NSView作为参数

代码语言:javascript
复制
- (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"];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50621473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档