Transform动画初解 in Swift
创建一个界面,就像这样的:

顶部是一个UISegmentControl,用来制定transform的类型。分别是:CGAffineTransformMakeTranslation、CGAffineTransformTranslate、CGAffineTransformIdentity.
然后是一个UILabel,这个Label实时的显示当前的动画类型是什么。
桔色的是动画的View。
最下面是一个按钮,按这个按钮桔色的View开始执行动画。
其他的,蓝色的线就是这几个View的Constraints。指定这几个view的定位是如何的,比如,相对于顶部的距离,相对于左边的距离,右边的距离等。
配置好页面上的View之后,给这些View在Controller中指定对应的对象。并在nib文件中指定各个View的事件。
View在controller中对应的对象:
@IBOutlet weak var animationView: UIView!
@IBOutlet weak var animationLabel: UILabel!
UISegmentControl的事件:
    @IBAction func segmentAction(sender: AnyObject) {
        var segmentControl = sender as UISegmentedControl
        animationType = segmentControl.selectedSegmentIndex
    }
运行动画的按钮的事件:
@IBAction func runAction(sender: AnyObject) {
        var distance: CGFloat =
        switch animationType {
        case :
            self.animationLabel.text = "CGAffineTransformMakeTranslation"
            UIView.animateWithDuration(1.0, animations: {
                self.animationView.transform = CGAffineTransformMakeTranslation(distance, )
            })
        case :
            self.animationLabel.text = "CGAffineTransformTranslate"
            UIView.animateWithDuration(1.0, animations: {
                self.animationView.transform = CGAffineTransformTranslate(self.animationView.transform, distance, )
            })
        case :
            self.animationLabel.text = "CGAffineTransformIdentity"
            UIView.animateWithDuration(1.0, animations: {
                self.animationView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, distance, )
            })
        default:
            println("")
        }
    }
在ViewDidLoad设置选择的动画的类型,这里我们不直接取UISegmentControl的selectedIndex的值。所以,在ViewDidLoad方法内设定默认值是1(即选定到是第一个)。
全部代码:
//
// ViewController.swift
// TransformDemo
//
// Created by Bruce Lee on 30/11/14.
// Copyright (c) 2014 Dynamic Cell. All rights reserved.
//
// QQ:1828099940, 群:58099570 欢迎加入讨论
// import UIKit class ViewController: UIViewController { @IBOutlet weak var animationView: UIView!
@IBOutlet weak var animationLabel: UILabel! var animationType: Int! override func viewDidLoad() {
super.viewDidLoad() animationType =
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} @IBAction func segmentAction(sender: AnyObject) {
var segmentControl = sender as UISegmentedControl
animationType = segmentControl.selectedSegmentIndex
} @IBAction func runAction(sender: AnyObject) {
var distance: CGFloat =
switch animationType {
case :
self.animationLabel.text = "CGAffineTransformMakeTranslation"
UIView.animateWithDuration(1.0, animations: {
self.animationView.transform = CGAffineTransformMakeTranslation(distance, )
})
case :
self.animationLabel.text = "CGAffineTransformTranslate"
UIView.animateWithDuration(1.0, animations: {
self.animationView.transform = CGAffineTransformTranslate(self.animationView.transform, distance, )
})
case :
self.animationLabel.text = "CGAffineTransformIdentity"
UIView.animateWithDuration(1.0, animations: {
self.animationView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, distance, )
})
default:
println("")
}
}
}
Transform动画初解 in Swift的更多相关文章
- transform动画效果
		
transform动画效果 transform :移动,旋转.倾斜.缩放. transform:translate(0,300px); x代表的是水平的偏移距离,y代表垂直的. t ...
 - 教你实现类似于格瓦拉启动页中的放大转场动画(OC&Swift)
		
教你实现类似于格瓦拉启动页中的放大转场动画(OC&Swift) 一.前言 用过格瓦拉电影,或者其他app可能都知道,一种点击按钮用放大效果实现转场的动画现在很流行,效果大致如下 在iOS中,在 ...
 - css3 transform动画效果与公司框架简易动画的差异
		
先看一下该网站的效果 http://2014guangzhouchezhan.dongfeng-citroen.com.cn/mobile/ 该站里面的动画效果由简易动画与css3动画2种方式混合达到 ...
 - transform动画的一个3D的正方体盒子
		
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
 - vue slot的使用(transform动画)
		
slot的说明就看vue的官方文档 但是有点模糊 理解: 是对组件的扩展,通过slot插槽向组件内部指定位置传递内容,通过slot可以父子传参: 解决什么问题:正常情况下,<Child&g ...
 - iOS 原生库(AVFoundation)实现二维码扫描,封装的工具类,不依赖第三方库,可高度自定义扫描动画及界面(Swift 4.0)
		
Create QRScanner.swift file // // QRScanner.swift // NativeQR // // Created by Harvey on 2017/10/24. ...
 - transform动画
		
1. html 结构 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
 - transform 动画效果
		
http://www.css88.com/tool/css3Preview/Transform.html transform的含义是:改变,使…变形:转换 transform的属性包括:rotate( ...
 - 移动端动画使用transform提升性能
		
在移动端做动画,对性能要求较高而通常的改变margin属性是性能极低的,即使使用绝对定位改变top,left这些属性性能也很差因此应该使用transform来进行动画效果,如transform:tra ...
 
随机推荐
- laravel Hash密码 校对
			
laravel加密 是使用hash不可逆的,但是可以对加密后的密码进行校对 $data = $r->all();$id = $data['id'];$user_password = bcrypt ...
 - selenium+python  移动鼠标方法
			
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver=we ...
 - .NET 4.5 HttpClient 中使用Cookie
			
为了使用.NET 4.5的HttpClient从WIN2K3换成了WIN7.装VS2010,结果告诉我VS2010不支持.NET 4.5.又装VS2012,接着装.NET FRAMEWORK 4.5. ...
 - C++ 类外定义
			
类内定义与内联函数 像下面这种函数名与函数体都写在类里面的函数形式被称作类内定义,编译器编译的时候会把它默认成内联函数. class Student { public: void setAge(int ...
 - python命令行中import caffe报错的解决方案
			
1.ImportError: No module named skimage.io >>> import caffe Traceback (most recent call last ...
 - Ubuntu 升级内核版本
			
查看当前内核版本 sch01ar@ubuntu:~$ uname -r Ubuntu 内核地址:https://kernel.ubuntu.com/~kernel-ppa/mainline/ 打开这个 ...
 - 利用 Babel 玩转你的代码
			
我在团队帮助开发 Node 工具时,遇到了需要对多份相似的代码进行一定的处理,但又不能改变原本仓库的代码,这个非常像我们的编译工具做的事情.在一开始的时候,参考了类似 FIS 的功能,简单参照使用代码 ...
 - 在 ubuntu1604 中 搭建 i 屁 sec 虚拟专用连接服务器
			
1.wget https://git.io/vpnsetup -O vpnsetup.sh 2.vim vpnsetup.sh 修改一些内容: 主要有三个参数:IPSEC的预共享秘钥,用户名,密码 3 ...
 - D3D-GetBackBuffer &GetFrontBufferData 抓屏&D3D抓取GPU数据
			
HRESULT GetBackBuffer( [in] UINT iSwapChain, [in] UINT ...
 - libcurl 调用curl_easy_getinfo( ) 返回错误码对照
			
//执行设置好的操作 res = curl_easy_perform(easy_handle); //获取HTTP错误码 ; curl_easy_getinfo(easy_handle, CURLIN ...