zoukankan      html  css  js  c++  java
  • [Xcode 实际操作]六、媒体与动画-(8)使用CATransaction Reveal制作渐显动画

    目录:[Swift]Xcode实际操作

    本文将演示如何制作渐显动画。

    图片的不透明度逐渐发生了变化,从而产生作渐显动画的效果。

    在项目导航区,打开视图控制器的代码文件【ViewController.swift】

     1 import UIKit
     2 
     3 class ViewController: UIViewController {
     4 
     5     override func viewDidLoad() {
     6         super.viewDidLoad()
     7         // Do any additional setup after loading the view, typically from a nib.
     8         
     9         //创建一个位置在(0,100),尺寸为(320,211)的显示区域
    10         let rect = CGRect(x: 0, y: 100,  320, height: 211)
    11         //初始化一个图像视图,并设置其位置和尺寸信息
    12         let imageView = UIImageView(frame: rect)
    13         
    14         //从项目资源文件中加载一张图片
    15         let image = UIImage(named: "Picture")
    16         //给图像视图指定需要显示的图片
    17         imageView.image = image
    18         
    19         //将图像视图,添加到当时视图控制器的根视图
    20         self.view.addSubview(imageView)
    21         
    22         //可以使用两种方法来实现动画效果
    23         //方法一:视图层面的
    24         //方法二:使用过渡动画
    25         //它实现了层的过渡动画,因此可以进行更低层次的控制
    26         let animation = CATransition()
    27         //设置动画的时长为2秒
    28         animation.duration = 2
    29         //设置动画的播放速度为由慢至快
    30         animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)
    31         //设置动画的类型为渐显动画
    32         animation.type = CATransitionType.reveal
    33         
    34         //将动画指定给图像视图的层
    35         imageView.layer.add(animation, forKey: "Reveal")
    36     }
    37 
    38     override func didReceiveMemoryWarning() {
    39         super.didReceiveMemoryWarning()
    40         // Dispose of any resources that can be recreated.
    41     }
    42 }
  • 相关阅读:
    fastjson 解析 字符串 为对象
    fastjson 对类模板进行 parseObject
    VUE路由跳转传递参数的几种方式
    ES 常用设置修改
    springboot图片路径形式获取图片
    Elasticsearch根据ID进行查询
    linux 常用命令
    Elasticsearch常用操作
    java8 stream接口终端操作 count,anyMatch,allMatch,noneMatch
    logstash数据迁移
  • 原文地址:https://www.cnblogs.com/strengthen/p/10034495.html
Copyright © 2011-2022 走看看