有人可以给我提供一个在 swift 中为 ImageView 的不透明度设置动画的示例吗?
我什至无法在 objective-c 中找到一个好的例子
func showCorrectImage(element: AnyObject){
var animation : CABasicAnimation = CABasicAnimation(keyPath: "opacity");
animation.delegate = self
animation.fromValue = NSValue(nonretainedObject: 0.0)
animation.toValue = NSValue(nonretainedObject: 1.0)
animation.duration = 1.0
element.layer?.addAnimation(animation, forKey: nil)
}
我想我有大部分权利(虽然不完全确定),有人可以帮助我吗?
元素 = ImageView
提前致谢!~
最佳答案
如果你需要一个简单的动画,为什么不使用 UIView 的 animateWithDuration:animations:
方法呢?
imageView.alpha = 0
UIView.animateWithDuration(1.0) {
imageView.alpha = 1
}
关于swift - 如何使用 swift 为不透明度设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36550692/