在iPhone上摇晃视觉效果(不摇动设备) [英] Shake visual effect on iPhone (NOT shaking the device)

查看:292
本文介绍了在iPhone上摇晃视觉效果(不摇动设备)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录失败时,我宁愿避免显示警报,也不会过时。显示警报然后在登录屏幕上的某处显示文本似乎是重复。

On login failure, I'd prefer to avoid showing an alert, it's too fleeting. Showing the alert and then showing the text somewhere on the login screen seems like duplication.

所以我希望它在用户输入时以图形方式摇动我的登录视图错误的用户ID和密码就像Mac登录屏幕一样。

So I'd like for it to graphically shake my login view when the user enters the wrong user ID and password like the Mac login screen does.

任何人都知道是否有办法解决此问题,或者对我可以使用的其他效果有任何建议?

Anyone know if there's a way to pull this off, or have any suggestions for another effect I could use?

推荐答案

我认为这是一个更有效的解决方案:

I think this is a more efficient solution:

Swift :

let anim = CAKeyframeAnimation( keyPath:"transform" )
anim.values = [
    NSValue( CATransform3D:CATransform3DMakeTranslation(-5, 0, 0 ) ),
    NSValue( CATransform3D:CATransform3DMakeTranslation( 5, 0, 0 ) )
]
anim.autoreverses = true
anim.repeatCount = 2
anim.duration = 7/100

viewToShake.layer.addAnimation( anim, forKey:nil )

Obj-C:

CAKeyframeAnimation * anim = [ CAKeyframeAnimation animationWithKeyPath:@"transform" ] ;
anim.values = @[ 
    [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f) ], 
    [ NSValue valueWithCATransform3D:CATransform3DMakeTranslation( 5.0f, 0.0f, 0.0f) ] 
] ;
anim.autoreverses = YES ;
anim.repeatCount = 2.0f ;
anim.duration = 0.07f ;

[ viewToShake.layer addAnimation:anim forKey:nil ] ;

只创建一个动画对象,并且全部在CoreAnimation级别执行。

Only one animation object is created and it's all performed at the CoreAnimation level.

这篇关于在iPhone上摇晃视觉效果(不摇动设备)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆