zoukankan      html  css  js  c++  java
  • Swift

    设置视图对象的transform属性,可以实现各种动画效果。


    1,移动
    指在同一平面内,将控件按照某个直线方向平移一定的距离。
    1
    2
    3
    4
    5
    //每次都从当前位置平移
    self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, -2.1, -2.1)
     
    //每次都从最开始的位置计算平移
    self.imageView.transform = CGAffineTransformMakeTranslation(2.3, 2.3)


    2,旋转

    1
    2
    3
    4
    5
    6
    7
    8
    //连续旋转
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(3.0) //设置动画时间
    self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, CGFloat(-M_PI/2))
    UIView.commitAnimations()
     
    //独立旋转,以初始位置旋转
    self.imageView.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI/4))


    3,缩放

    1
    2
    3
    4
    5
    6
    7
    8
    //连续缩放
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(3.0) //设置动画时间
    self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 1.5 ,1.5)
    UIView.commitAnimations()
     
    //独立缩放,以初始位置缩放
    self.imageView.transform = CGAffineTransformMakeScale(1.3, 1.3)


    4,反转

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    //返回初始状态
    self.imageView.transform = CGAffineTransformIdentity
     
    //连续反转
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(3.0) //设置动画时间
    self.imageView.transform = CGAffineTransformConcat(self.imageView.transform,
        CGAffineTransformInvert(self.imageView.transform))
    UIView.commitAnimations()
     
    //独立反转,以初始位置反转
    self.imageView.transform = CGAffineTransformInvert(self.imageView.transform)
  • 相关阅读:
    html/form表单常用属性认识
    css复杂动画(animation属性)
    css样式水平居中和垂直居中的方法
    css简单动画(transition属性)
    html/css中map和area的应用
    html/css弹性布局的几大常用属性详解
    webpack优化配置
    webpack配置详解
    使用Node.js搭建一个简单的web服务器(二):搭建一个简单的服务器
    使用Node.js搭建一个简单的web服务器(一):Node.js入门
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/4843438.html
Copyright © 2011-2022 走看看