受到Fabric - Answers动画启发的专门为UIView自定义的动画。
要创建第一个动画,您只需要了解一个方法
/**
Designated initializer for puzzle animation and it's subclasses
- parameter viewToAnimate: view to render into pieces
- parameter configuration: animation configuration
- returns: newly created animation instance
*/
init(viewToAnimate: UIView, configuration: PuzzleAnimationConfiguration = PuzzleAnimationConfiguration())
它很灵活 - 您可以配置动画的几乎所有参数
/**
* Defines the structure that contains configurable parameters for puzzle animation
*/
struct PuzzleAnimationConfiguration {
/// Defines the animation velocity. Higher velocity less animation duration
var animationVelocity: NSTimeInterval = 1
/// Defines the delay between each piece in piece's group animation
var pieceAnimationDelay: PuzzleAnimationDelay = defaultForwardPieceAnimationDelay
/// Defines the delay between each group of pieces animation
var pieceGroupAnimationDelay: PuzzleAnimationDelay = defaultForwardPieceGroupAnimationDelay
/// Defines the animation piece's scale
var animationScale: Double = 2.5
/// Each piece represents square and this value represents the number of pixels of square side
var pieceSide: CGFloat = 40
}
处理有关状态的回调以启动新动画或执行其他操作
/// Called when animation completed, stoped or failed
/// @note You can set it any time even during the animation
public var animationCompletion: PuzzleAnimationCompletion?
直观且简单的接口
/**
Starts the animation. Makes view to animate hidden
*/
public func start()
/**
Stops the animation. Removes all pieces from superview. Makes view to animate visible
*/
public func stop()
完整示例请查看viewController.swift