我试图弄清楚当用户将文本字段留空时如何在按钮按下时使文本摇动.
我目前有以下代码工作:
if self.subTotalAmountData.text == "" {
let alertController = UIAlertController(title: "Title", message:
"What is the Sub-Total!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
} else {
}
Run Code Online (Sandbox Code Playgroud)
但我认为将文本字段震动作为警报会更具吸引力.
我找不到任何动画文本字段的动画.
有任何想法吗?
谢谢!
如何添加动画来UITextField指示错误的密码,就像Facebook应用程序(登录屏幕)或Mac OS X登录框中的密码一样?
先感谢您.
我一直在努力实现这个,但找不到任何代码可以动摇它像iPhone应用程序震动删除它们!
CABasicAnimation *animation =
[CABasicAnimation animationWithKeyPath:@"position"];
[animation setDuration:0.05];
[animation setRepeatCount:8];
[animation setAutoreverses:YES];
[animation setFromValue:[NSValue valueWithCGPoint:
CGPointMake([lockView center].x - 20.0f, [lockView center].y)]];
[animation setToValue:[NSValue valueWithCGPoint:
CGPointMake([lockView center].x + 20.0f, [lockView center].y)]];
[[lockView layer] addAnimation:animation forKey:@"position"];
Run Code Online (Sandbox Code Playgroud) 在很多情况下你需要"摇动"UIView.
(例如,"吸引儿童用户注意控件","连接速度慢","用户输入错误输入"等等.)
使用UIKit Dynamics可以做到这一点吗?
所以你必须......
采取观点,比如说0,0
添加一个春天的概念
给它一个轻推,对"左"说
它应该在弹簧上向后摆动,最终再次稳定在0,0
这可能吗?我在Apple演示中找不到一个例子.干杯
请注意,正如Niels在下面明确地解释的那样,弹簧不一定是你想要的某些情况的"物理感觉":在其他情况下它可能是完美的.据我所知,iOS自己的应用程序(例如消息等)中的所有物理现在都使用了UIKit Dynamics,所以对我而言,值得一提的是"UIView弹跳弹簧".
为了清楚起见,当然你可以做一些"相似"的事情,只需动画即可.例...
但现在,这与iOS的其他部分没有相同的"物理感觉".
-(void)userInputErrorShake
{
[CATransaction begin];
CAKeyframeAnimation * anim =
[CAKeyframeAnimation animationWithKeyPath:@"transform"];
anim.values = @[
[NSValue valueWithCATransform3D:
CATransform3DMakeTranslation(-4.0f, 0.0f, 0.0f) ],
[NSValue valueWithCATransform3D:
CATransform3DMakeTranslation(4.0f, 0.0f, 0.0f) ]
];
anim.autoreverses = YES;
anim.repeatCount = 1.0f;
anim.duration = 0.1f;
[CATransaction setCompletionBlock:^{}];
[self.layer addAnimation:anim forKey:nil];
[CATransaction commit];
}
Run Code Online (Sandbox Code Playgroud) ios ×3
game-physics ×1
ios7 ×1
iphone ×1
objective-c ×1
swift ×1
uiimageview ×1
uitextfield ×1