iOS 文本動畫

iOS動畫分為顯示動畫(keyFrameAnimation PropertyAnimation CATransaction)隱式動畫 CATransaction表示一個動畫事務,可以設置layer層的屬性,再結合CAAnimation即可實現動畫效果

           class func textLayerAnimation(layer: CALayer, durationTime: TimeInterval, delay: TimeInterval, effectAnimationClosure: effectAnimationLayerClosure?,finishedClosure: completionClosure?) -> Void{
        let animationObjct = TELayerAnimation()
        DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
            let oldLayer = animationObjct.animatableLayerCopy(layer: layer)
            var newLayer: CALayer?
            var animationGroup: CAAnimationGroup?
            animationObjct.completionBlock = finishedClosure
            if let effectAnimationClosure = effectAnimationClosure{
                CATransaction.begin()
                //關閉隱式動畫
                CATransaction.setDisableActions(true)
                newLayer = effectAnimationClosure(layer)
                CATransaction.commit()
            }
            animationGroup = animationObjct.groupAnimationWithLayerChanges(old: oldLayer, new: newLayer!)
            if let textAnimationGroup = animationGroup{
                animationObjct.textLayer = layer
                textAnimationGroup.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionEaseInEaseOut)
                textAnimationGroup.beginTime = CACurrentMediaTime()
                textAnimationGroup.duration = durationTime
                textAnimationGroup.delegate = animationObjct
                layer.add(textAnimationGroup, forKey: textAnimationGroupKey)
            }else{
                if finishedClosure != nil{
                    finishedClosure!(true)
                }
            }
        }
    }  
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺ios動畫全貌。在這里你可以看...
    每天刷兩次牙閱讀 8,562評論 6 30
  • 概覽 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你...
    Yiart閱讀 3,864評論 3 34
  • 在iOS中隨處都可以看到絢麗的動畫效果,實現這些動畫的過程并不復雜,今天將帶大家一窺iOS動畫全貌。在這里你可以看...
    F麥子閱讀 5,141評論 5 13
  • 基礎概念 iOS圖形架構 核心動畫是 iOS 和 MacOS 上的圖形渲染和動畫基礎結構,用于為應用的視圖和...
    荒漠現甘泉閱讀 1,284評論 0 3
  • 什么是動畫 動畫,顧名思義,就是能“動”的畫。 人的眼睛對圖像有短暫的記憶效應,所以當眼睛看到多張圖片連續快速的切...
    CoderSC閱讀 1,316評論 0 1