//
// TurnAnimation.swift
// TurnAnimation
//
// Created by 王渊博 on 15/12/2.
// Copyright © 2015年 浮云千载唯忆君颜. All rights reserved.
//
import UIKit
import QuartzCore
class TurnAnimation: NSObject {
// 旋转动画
class func turnAnimationWithAnimaView(animaView animaView: UIView, fromValue: AnyObject, toValue: AnyObject, duration: CFTimeInterval) {
// 旋转
let animation = CATransition.init()
animation.duration = 0.1
animation.repeatCount = 5
animation.fillMode = kCAFillModeForwards
animation.removedOnCompletion = false
animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)
animation.type = "oglFlip"
animation.subtype = "fromLeft"
animaView.layer.addAnimation(animation, forKey: nil)
// 缩放
let anima = CABasicAnimation.init(keyPath: "transform.scale")
anima.fillMode = kCAFillModeForwards
anima.removedOnCompletion = false
anima.fromValue = fromValue // as AnyObject
anima.toValue = toValue // as AnyObject
anima.duration = duration
anima.autoreverses = false
anima.repeatCount = 1
animaView.layer.addAnimation(anima, forKey: nil)
animaView.layer.fillMode = kCAFillModeForwards
}
// 圆形动画
class func keyframeAnimation(animaView: UIView, rect: CGRect, duration: CFTimeInterval, repeatCount: Float) {
// 路径
let ctx = UIGraphicsGetCurrentContext()
let path = CGPathCreateMutable()
CGPathAddEllipseInRect(path, nil, rect)
CGContextAddPath(ctx, path)
CGContextStrokePath(ctx)
let animation = CAKeyframeAnimation.init(keyPath: "position")
animation.path = path
animation.removedOnCompletion = false
animation.fillMode = kCAFillModeForwards
animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseIn)
animation.autoreverses = false
animation.duration = duration
animation.repeatCount = repeatCount
animaView.layer.addAnimation(animation, forKey: "position")
}
}
网友评论