-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from mono0926/enhance-animatable-path
Enhance animatable path
- Loading branch information
Showing
8 changed files
with
49 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
// | ||
// HasAnimatablePath.swift | ||
// HasAnimatableLayer.swift | ||
// NativePopup | ||
// | ||
// Created by mono on 2017/05/21. | ||
// Created by mono on 2017/05/20. | ||
// Copyright © 2017 mono. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
open class AnimatablePathView: UIView, HasAnimatableLayer { | ||
let animatableLayer = CAShapeLayer() | ||
open var animatablePath: UIBezierPath { fatalError("Should be overridden.") } | ||
func setupLayer() { | ||
public protocol HasAnimatablePath: Animatable { | ||
var layer: CALayer { get } | ||
var tintColor: UIColor! { get } | ||
/** Should return same instance */ | ||
var animatableLayer: CAShapeLayer { get } | ||
var animatablePath: UIBezierPath { get } | ||
} | ||
|
||
public extension HasAnimatablePath { | ||
public func animate() { | ||
let animation = CABasicAnimation(keyPath: "strokeEnd") | ||
animation.duration = duration | ||
animation.fromValue = 0 | ||
animation.toValue = 1 | ||
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) | ||
animatableLayer.strokeEnd = 1 | ||
animatableLayer.add(animation, forKey: "animation") | ||
} | ||
public func configureAnimatableLayer() { | ||
animatableLayer.path = animatablePath.cgPath | ||
animatableLayer.fillColor = UIColor.clear.cgColor | ||
animatableLayer.strokeColor = tintColor.cgColor | ||
animatableLayer.strokeColor = tintColor?.cgColor | ||
animatableLayer.lineWidth = 9 | ||
animatableLayer.lineCap = kCALineCapRound | ||
animatableLayer.lineJoin = kCALineCapRound | ||
animatableLayer.strokeEnd = 0 | ||
layer.addSublayer(animatableLayer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters