ios - 如何使 UIImageView 闪烁/闪烁动画无限?
问题描述
我正在尝试在我的 iOS 应用程序中为 UIImageView 实现一段时间的闪烁/闪烁效果。我希望 UIImageView 使用 alpha 闪烁/闪烁,而不是使用不同的图像。
我有另一个来自 android 应用程序的代码片段,它描述了我试图在 XCode Swift 中实现的目标。我把它贴在下面:
这是我迄今为止在 XCode Swift 中所取得的成就:
ellipses.alpha=0.8
ellipses.animationDuration=1
ellipses.animationRepeatCount=0
ellipses.startAnimating()
当然,它不起作用!我不太确定如何实现这一目标,并且很乐意获得一些指导。
下面的代码适用于 android,而不适用于 Swift/Xcode(但它描述了我的目标非常明确)
Animation animation = new AlphaAnimation(1, 0); //to change visibility from visible to invisible
animation.setDuration(1000); //1 second duration for each animation cycle
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE); //repeating indefinitely
animation.setRepeatMode(Animation.REVERSE); //animation will start from end point once ended.
imageButton.startAnimation(animation); //to start animation
解决方案
您可以反复为图像视图的不透明度设置动画。就像是:
UIView.animate(withDuration: 2.0,
delay: 0,
options: [.repeat, .autoreverse],
animations: { imageView.alpha = 0 }
)
推荐阅读
- python-3.x - 如何将条件语句转换为简单表达式?以这种方式复合回报是否可以接受?
- javascript - 返回 node.js (fs.readFileSync) 中的目录
- c# - 如何匹配完全匹配之后出现的任何内容,而不包括匹配本身?
- java - 为什么这种方法不打开文件并写入文件?
- sql - SQL left join 进行 3 对 1 匹配,无需替换
- python - 在熊猫组中,除了一列之外的所有列都是相同的
- 3d - ARKit 和录制/回放图像+深度与时间流逝
- kubernetes - 是否有任何方法可以为 IBM Cloud Kubernetes Service Cli 打开与 kubectl 相同的自动完成功能?
- c++ - 将 vec3 乘以模型矩阵的问题(缩放问题)
- java - 如何将嵌入式和关系添加到房间数据库