Xcode9学习笔记54 - 使用CATransaction Reveal制作动画
程序员文章站
2024-03-23 21:02:28
...
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let rect = CGRect(x: 0, y: 0, width: 499, height: 726)
let imageView = UIImageView(frame: rect)
let image = UIImage(named: "Pic3")
imageView.image = image//给图像视图添加要显示的图片
self.view.addSubview(imageView)
let animation = CATransition()
animation.duration = 2//设置动画时长2秒
//设置动画的播放速度为由慢至块
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
animation.type = kCATransitionReveal//设置动画的类型为渐显动画
imageView.layer.add(animation, forKey: "Reveal")//将动画指定给图像视图的层
}
上一篇: 前端面试题:JS中的原型和原型链