Xcode9学习笔记58 - 使用CATransaction Push制作动画(从左往右飘进图片)

    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 = kCATransitionPush//设置动画的类型为入场动画(图片从左往右飘进来)
        
        imageView.layer.add(animation, forKey: "Push")//将动画指定给图像视图的层
    }

  

posted on 2017-11-17 06:43  业余极客  阅读(305)  评论(0编辑  收藏  举报

导航