UITextField抖动效果

        我们登录或者注册的时候一般会输入密码和账号,当用户输入为空需要重新输入的时候,需要给用户一个提示.通常我们会用到UIAlerView,用提示框太俗太老套了,这里我们用一个抖动效果来提示用户重新输入......

       请看以下代码:(为了方便广大程序猿们复制繁琐的代码, 请看文章最底部)



- (void)shake

{

    CAKeyframeAnimation *keyAn = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    [keyAn setDuration:.3f];

    NSArray *array = [[NSArray alloc] initWithObjects:

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x-5, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x+5, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x-5, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x+5, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x-5, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x+5, self.field.center.y)],

                      [NSValue valueWithCGPoint:CGPointMake(self.field.center.x, self.field.center.y)],

                      nil];

    [keyAn setValues:array];


    // 添加动画

    [self.field.layer addAnimation:keyAn forKey:@"text"];

}


                  不用谢我哦亲






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值