//
//  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")
        
    }
}
Swift2垂直旋转+放大动画代码
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- // UIView如果使用AutoLayout 必须写此方法 //按钮的动态效果修改时 此方法为 系统自带方法 /...
 - http://www .jq-school.com/Show.aspx?id=281
 - “每日一练”刚开始一天就遭到了一些阻力,似乎该改名叫"每周一练"ORZ。。。还是再逼迫自己坚持一下试试(ˇˍˇ)...