From 23594868c62a5266f7be9d12b08a0bfe2ca6420a Mon Sep 17 00:00:00 2001 From: Victor Sukochev Date: Fri, 1 Apr 2016 14:58:14 +0600 Subject: [PATCH] Helpful extensions --- Example/Example/ThirdPageViewController.swift | 7 +++---- Source/animation/types/AnimationSequence.swift | 11 +++++++++++ Source/animation/types/LoopedAnimation.swift | 6 ++++++ Source/animation/types/RepetitiveAnimation.swift | 11 +++++++++++ Source/animation/types/RevertedAnimation.swift | 7 +++++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Example/Example/ThirdPageViewController.swift b/Example/Example/ThirdPageViewController.swift index b1f2d662..57f28970 100644 --- a/Example/Example/ThirdPageViewController.swift +++ b/Example/Example/ThirdPageViewController.swift @@ -143,10 +143,9 @@ class ThirdPageCustomView: MacawView { finalValue:Transform.move(220, my: 420).scale(0.15, sy: 0.15), animationDuration: 1.5) - let animationSequence = AnimationSequence(animations: [cloud1ShapeAnimation, cloud2ShapeAnimation, cloud3ShapeAnimation]) - let loopedAnimation = LoopedAnimation(animation:animationSequence) - let animationLoop = RepetitiveAnimation(animation: loopedAnimation) - super.addAnimation(animationLoop) + let animation = [cloud1ShapeAnimation, cloud2ShapeAnimation, cloud3ShapeAnimation].sequence().looped().infiniteLoop() + super.addAnimation(animation) + // super.addAnimation(cloud1ShapeAnimation) // super.addAnimation(cloud2ShapeAnimation) // super.addAnimation(cloud3ShapeAnimation) diff --git a/Source/animation/types/AnimationSequence.swift b/Source/animation/types/AnimationSequence.swift index c277ca83..e376a617 100644 --- a/Source/animation/types/AnimationSequence.swift +++ b/Source/animation/types/AnimationSequence.swift @@ -1,5 +1,16 @@ import Foundation +public extension SequenceType where Generator.Element: CommonAnimation{ + public func sequence() -> CommonAnimation { + let sequence = AnimationSequence(animations:[]) + self.forEach { animation in + sequence.addAnimation(animation) + } + + return sequence + } +} + public class AnimationSequence: CommonAnimation { var sequence: [CommonAnimation] = [] diff --git a/Source/animation/types/LoopedAnimation.swift b/Source/animation/types/LoopedAnimation.swift index 3fe7ece0..0e58e22e 100644 --- a/Source/animation/types/LoopedAnimation.swift +++ b/Source/animation/types/LoopedAnimation.swift @@ -1,5 +1,11 @@ import Foundation +public extension CommonAnimation { + public func looped() -> CommonAnimation { + return LoopedAnimation(animation: self) + } +} + public class LoopedAnimation: CommonAnimation { var loopedlAnimation: CommonAnimation? diff --git a/Source/animation/types/RepetitiveAnimation.swift b/Source/animation/types/RepetitiveAnimation.swift index fdb95933..5901ff19 100644 --- a/Source/animation/types/RepetitiveAnimation.swift +++ b/Source/animation/types/RepetitiveAnimation.swift @@ -1,10 +1,21 @@ import Foundation + public enum RepetitiveAnimationType { case Finite case Infinite } +public extension CommonAnimation { + public func infiniteLoop() -> CommonAnimation { + return RepetitiveAnimation(animation: self) + } + + public func loop(count: Int) -> CommonAnimation { + return RepetitiveAnimation(animation: self, count: count) + } +} + public class RepetitiveAnimation: CommonAnimation { var loopAnimation: CommonAnimation? diff --git a/Source/animation/types/RevertedAnimation.swift b/Source/animation/types/RevertedAnimation.swift index 92cfc982..c5d8a7a7 100644 --- a/Source/animation/types/RevertedAnimation.swift +++ b/Source/animation/types/RevertedAnimation.swift @@ -1,5 +1,12 @@ import Foundation + +public extension CommonAnimation { + public func revert() -> CommonAnimation { + return RevertedAnimation(animation: self) + } +} + public class RevertedAnimation: CommonAnimation { var originalAnimation: CommonAnimation?