//
// ViewController.swift
// Anamation
//
// Created by su on 15/12/9.
// Copyright © 2015年 tian. All rights reserved.
//
//动画
//动画的主要属性
//Position xy坐标属性
//Opacity 透明度属性
//Scale 缩放属性
//其他属性 Color颜色属性 Rotate 旋转属性 3D属性
//动画师如何形成的? 1.动画开始时对象的属性2.动画结束时对象的属性3.动画执行的时间4.执行动画过程中会发生什么,5.动画结束后会发生什么
//动画曲线
//1.Linear 现行匀速变化
//2.Ease In 以慢速开始:加速变化
//3.Ease In, Ease Out 先加速后减速
//4.Ease Out 以慢速开始:减速变化
import UIKit
import CoreGraphics
import QuartzCore
class ViewController: UIViewController {
@IBOutlet weak var redBall1: UIView!
@IBOutlet weak var redBall2: UIView!
@IBOutlet weak var redBall3: UIView!
@IBOutlet weak var redBall4: UIView!
@IBOutlet weak var redBall5: UIView!
@IBOutlet weak var redBall6: UIView!
override func viewDidLoad() {
super.viewDidLoad()
//UIKit和Core Animation动画 原生 优点:简单.代码量少
//球的放大动画 灰色
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
self.redBall4.transform = CGAffineTransformMakeScale(2, 2)
}, completion: nil)
//组合动画和位移动画
//组合动画-CGAffineTransformConcat
UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
self.redBall1.transform = CGAffineTransformConcat(CGAffineTransformMakeScale(2, 2), CGAffineTransformMakeTranslation(100, 400))
self.redBall1.backgroundColor = UIColor.greenColor()
}, completion: nil)
// Spring Animation 弹性动画 usingSpringWithDamping阻尼值 蓝色
UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
self.redBall2.transform = CGAffineTransformConcat(CGAffineTransformMakeScale(2, 2), CGAffineTransformMakeTranslation(100, 200))
self.redBall2.backgroundColor = UIColor.blueColor()
}, completion: nil)
//JNWSpringAnimation 老外写的 优点:这个框架能够很细致的调整弹性动画属性
// JNW所支持的属性: bounds边界,position位置,rotation旋转,sacale缩放,corner圆角,shadow阴影
// 1.导入JNW框架
//获取JNW框架 https://github.com/jwilling/JNWSpringAnimation
//因为JNW框架是使用Object-C编写 所以需要创建桥接头文件, 在头文件中引入#import "JNWSpringAnimation.h" ---swift与object-c混编
//缩放动画 橘色
//创建JNW实例
let scale = JNWSpringAnimation(keyPath: "transform.scale")
//阻尼
scale.damping = 1
//伸展系数,弹簧伸缩的难度
scale.stiffness = 100
//质量 : 决定动画快慢的效果
scale.mass = 2
//设置初始值 和结束值
scale.fromValue = 1
scale.toValue = 2
//将JNW赋予redball
redBall3.layer.addAnimation(scale, forKey: scale.keyPath)
redBall3.transform = CGAffineTransformMakeScale(2, 2)
//旋转动画 红色
//创建JNW实例
let rotation = JNWSpringAnimation(keyPath: "transform.rotation")
//阻尼
rotation.damping = 1
rotation.stiffness = 100
rotation.mass = 2
rotation.fromValue = 0
rotation.toValue = M_PI_2
redBall5.layer.addAnimation(rotation, forKey: rotation.keyPath)
redBall5.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
//位移变化 粉色
let movie = JNWSpringAnimation(keyPath: "tranform.translation.y")
movie.damping = 6
movie.stiffness = 100
movie.mass = 2
movie.fromValue = 0
movie.toValue = 300
redBall6.layer.addAnimation(movie, forKey: movie.keyPath)
//JNWSpringAnimation 默认会还原初始状态,所以要动手设置的到结束状态
redBall6.transform = CGAffineTransformMakeTranslation(0, 300)
//Facebook Pop facebook开源动画引擎pop
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}