Commit 24b2bdfb by Daniel Dahan

updated MaterialAnimation internals and added delegation handling

parent ac8fb0e1
......@@ -18,6 +18,19 @@
import UIKit
@objc(MaterialAnimationDelegate)
public protocol MaterialAnimationDelegate {
/**
:name: materialAnimationDidStart
*/
optional func materialAnimationDidStart(animation: CAAnimation)
/**
:name: materialAnimationDidStop
*/
optional func materialAnimationDidStop(animation: CAAnimation, finished flag: Bool)
}
public typealias MaterialAnimationFillModeType = String
public enum MaterialAnimationFillMode {
......
......@@ -18,19 +18,6 @@
import UIKit
@objc(MaterialButtonDelegate)
public protocol MaterialButtonDelegate {
/**
:name: animationDidStart
*/
optional func animationDidStart(materialButton: MaterialButton, animation: CAAnimation)
/**
:name: animationDidStop
*/
optional func animationDidStop(materialButton: MaterialButton, animation: CAAnimation, finished flag: Bool)
}
@objc(MaterialButton)
public class MaterialButton : UIButton {
/**
......@@ -46,7 +33,7 @@ public class MaterialButton : UIButton {
/**
:name: delegate
*/
public weak var delegate: MaterialButtonDelegate?
public weak var delegate: MaterialAnimationDelegate?
/**
:name: pulseScale
......@@ -343,6 +330,7 @@ public class MaterialButton : UIButton {
prepareShape()
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
......@@ -356,13 +344,10 @@ public class MaterialButton : UIButton {
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
if true == filterAnimations(a) {
visualLayer.addAnimation(a, forKey: a.keyPath!)
}
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
filterAnimations(a)
visualLayer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
}
......@@ -370,7 +355,7 @@ public class MaterialButton : UIButton {
:name: animationDidStart
*/
public override func animationDidStart(anim: CAAnimation) {
delegate?.animationDidStart?(self, animation: anim)
delegate?.materialAnimationDidStart?(anim)
}
/**
......@@ -382,16 +367,14 @@ public class MaterialButton : UIButton {
MaterialAnimation.animationDisabled({
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
})
delegate?.materialAnimationDidStop?(anim, finished: flag)
}
layer.removeAnimationForKey(a.keyPath!)
visualLayer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
delegate?.animationDidStop?(self, animation: anim, finished: flag)
}
//
......
......@@ -18,19 +18,6 @@
import UIKit
@objc(MaterialViewDelegate)
public protocol MaterialViewDelegate {
/**
:name: animationDidStart
*/
optional func animationDidStart(materialView: MaterialView, animation: CAAnimation)
/**
:name: animationDidStop
*/
optional func animationDidStop(materialView: MaterialView, animation: CAAnimation, finished flag: Bool)
}
@objc(MaterialView)
public class MaterialView : UIView {
//
......@@ -41,7 +28,7 @@ public class MaterialView : UIView {
/**
:name: visualLayer
*/
public weak var delegate: MaterialViewDelegate?
public weak var delegate: MaterialAnimationDelegate?
/**
:name: image
......@@ -335,6 +322,7 @@ public class MaterialView : UIView {
prepareShape()
visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius
}
......@@ -348,13 +336,8 @@ public class MaterialView : UIView {
}
if let a: CAPropertyAnimation = animation as? CAPropertyAnimation {
layer.addAnimation(a, forKey: a.keyPath!)
if true == filterAnimations(a) {
visualLayer.addAnimation(a, forKey: a.keyPath!)
}
} else if let a: CAAnimationGroup = animation as? CAAnimationGroup {
layer.addAnimation(a, forKey: nil)
filterAnimations(a)
visualLayer.addAnimation(a, forKey: nil)
} else if let a: CATransition = animation as? CATransition {
layer.addAnimation(a, forKey: kCATransition)
}
......@@ -364,7 +347,7 @@ public class MaterialView : UIView {
:name: animationDidStart
*/
public override func animationDidStart(anim: CAAnimation) {
delegate?.animationDidStart?(self, animation: anim)
delegate?.materialAnimationDidStart?(anim)
}
/**
......@@ -376,16 +359,14 @@ public class MaterialView : UIView {
MaterialAnimation.animationDisabled({
self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
})
delegate?.materialAnimationDidStop?(anim, finished: flag)
}
layer.removeAnimationForKey(a.keyPath!)
visualLayer.removeAnimationForKey(a.keyPath!)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! {
animationDidStop(x, finished: true)
}
}
delegate?.animationDidStop?(self, animation: anim, finished: flag)
}
//
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment