ios - 如何晃动UIAlertController 中的UITextField
大家讲道理
大家讲道理 2017-04-17 16:18:06
[iOS讨论组]

当textfield 单独存在时 以下代码是可以晃动 textfield的

let animation = CAKeyframeAnimation()
animation.keyPath = "position.x"
animation.values = [0, 10, -10, 10, 0]
animation.keyTimes = [0, 1/6.0, 3/6.0, 5/6.0, 1]
animation.duration = 0.4
animation.additive = true
textField.layer.addAnimation(animation, forKey: "shake")

然而当textfield嵌在一个UIAlertController时就不起作用了,请问如何解决,如何晃动alertcontroller中的输入框或者晃动alertcontroller本身。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
怪我咯

可以试试这个:

let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.07
animation.repeatCount = 4
animation.autoreverses = true
animation.fromValue = NSValue(CGPoint: CGPointMake(txtField.center.x - 10, txtField.center.y))
animation.toValue = NSValue(CGPoint: CGPointMake(txtField.center.x + 10, txtField.center.y))
txtField.layer.addAnimation(animation, forKey: "position")

我没试过,不知道行不行。来自 stackoverflow

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号