Commit bf717d93 by Daniel Dahan

updated MaterialAnimation with fixes to issue-194

parent a0a9c77a
...@@ -60,6 +60,7 @@ class AppNavigationBarViewController: NavigationBarViewController { ...@@ -60,6 +60,7 @@ class AppNavigationBarViewController: NavigationBarViewController {
override func prepareView() { override func prepareView() {
super.prepareView() super.prepareView()
view.backgroundColor = MaterialColor.black view.backgroundColor = MaterialColor.black
navigationBarViewController?.delegate = self
} }
/// Toggle SideNavigationViewController left UIViewController. /// Toggle SideNavigationViewController left UIViewController.
...@@ -108,3 +109,25 @@ class AppNavigationBarViewController: NavigationBarViewController { ...@@ -108,3 +109,25 @@ class AppNavigationBarViewController: NavigationBarViewController {
} }
} }
extension AppNavigationBarViewController: NavigationBarViewControllerDelegate {
/// Delegation method that executes when the floatingViewController will open.
func navigationBarViewControllerWillOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Will Open")
}
/// Delegation method that executes when the floatingViewController will close.
func navigationBarViewControllerWillCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Will Close")
}
/// Delegation method that executes when the floatingViewController did open.
func navigationBarViewControllerDidOpenFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Did Open")
}
/// Delegation method that executes when the floatingViewController did close.
func navigationBarViewControllerDidCloseFloatingViewController(navigationBarViewController: NavigationBarViewController) {
print("Did Close")
}
}
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
965626701C88B7F4004ADEF7 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9656266F1C88B7F4004ADEF7 /* Material.framework */; };
965626711C88B7F4004ADEF7 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9656266F1C88B7F4004ADEF7 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
967513CA1C136BB7009F455A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513C91C136BB7009F455A /* AppDelegate.swift */; }; 967513CA1C136BB7009F455A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513C91C136BB7009F455A /* AppDelegate.swift */; };
967513CC1C136BB7009F455A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513CB1C136BB7009F455A /* ViewController.swift */; }; 967513CC1C136BB7009F455A /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967513CB1C136BB7009F455A /* ViewController.swift */; };
967513D11C136BB7009F455A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 967513D01C136BB7009F455A /* Assets.xcassets */; }; 967513D11C136BB7009F455A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 967513D01C136BB7009F455A /* Assets.xcassets */; };
...@@ -22,7 +20,6 @@ ...@@ -22,7 +20,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
965626711C88B7F4004ADEF7 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -30,7 +27,6 @@ ...@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
9656266F1C88B7F4004ADEF7 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
967513C61C136BB7009F455A /* CardView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CardView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 967513C61C136BB7009F455A /* CardView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CardView.app; sourceTree = BUILT_PRODUCTS_DIR; };
967513C91C136BB7009F455A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 967513C91C136BB7009F455A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
967513CB1C136BB7009F455A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; 967513CB1C136BB7009F455A /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
965626701C88B7F4004ADEF7 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +49,6 @@ ...@@ -54,7 +49,6 @@
967513BD1C136BB7009F455A = { 967513BD1C136BB7009F455A = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9656266F1C88B7F4004ADEF7 /* Material.framework */,
967513C81C136BB7009F455A /* CardView */, 967513C81C136BB7009F455A /* CardView */,
967513C71C136BB7009F455A /* Products */, 967513C71C136BB7009F455A /* Products */,
); );
......
...@@ -58,45 +58,6 @@ class ViewController: UIViewController { ...@@ -58,45 +58,6 @@ class ViewController: UIViewController {
:description: General usage example. :description: General usage example.
*/ */
private func prepareGeneralCardViewExample() { private func prepareGeneralCardViewExample() {
// let cardView: CardView = CardView()
//
// // Title label.
// let titleLabel: UILabel = UILabel()
// titleLabel.text = "Welcome Back!"
// titleLabel.textColor = MaterialColor.blue.darken1
// titleLabel.font = RobotoFont.mediumWithSize(20)
// cardView.titleLabel = titleLabel
//
// // Detail label.
// let detailLabel: UILabel = UILabel()
// detailLabel.text = "It’s been a while, have you read any new books lately?"
// detailLabel.numberOfLines = 0
// cardView.detailView = detailLabel
//
// // Yes button.
// let btn1: FlatButton = FlatButton()
// btn1.pulseColor = MaterialColor.blue.lighten1
// btn1.pulseScale = false
// btn1.setTitle("YES", forState: .Normal)
// btn1.setTitleColor(MaterialColor.blue.darken1, forState: .Normal)
//
// // No button.
// let btn2: FlatButton = FlatButton()
// btn2.pulseColor = MaterialColor.blue.lighten1
// btn2.pulseScale = false
// btn2.setTitle("NO", forState: .Normal)
// btn2.setTitleColor(MaterialColor.blue.darken1, forState: .Normal)
//
// // Add buttons to left side.
// cardView.leftButtons = [btn1, btn2]
//
// // To support orientation changes, use MaterialLayout.
// view.addSubview(cardView)
// cardView.translatesAutoresizingMaskIntoConstraints = false
// MaterialLayout.alignFromTop(view, child: cardView, top: 100)
// MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
let cardView: CardView = CardView() let cardView: CardView = CardView()
// Title label. // Title label.
...@@ -134,8 +95,6 @@ class ViewController: UIViewController { ...@@ -134,8 +95,6 @@ class ViewController: UIViewController {
cardView.translatesAutoresizingMaskIntoConstraints = false cardView.translatesAutoresizingMaskIntoConstraints = false
MaterialLayout.alignFromTop(view, child: cardView, top: 100) MaterialLayout.alignFromTop(view, child: cardView, top: 100)
MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20) MaterialLayout.alignToParentHorizontally(view, child: cardView, left: 20, right: 20)
cardView.animate(MaterialAnimation.translateY(200))
} }
/** /**
......
...@@ -43,7 +43,6 @@ class ViewController: UIViewController { ...@@ -43,7 +43,6 @@ class ViewController: UIViewController {
prepareFlatButtonExample() prepareFlatButtonExample()
prepareRaisedButtonExample() prepareRaisedButtonExample()
prepareFabButtonExample() prepareFabButtonExample()
// prepareFabButtonAnimationExample()
} }
/// General preparation statements. /// General preparation statements.
...@@ -81,25 +80,5 @@ class ViewController: UIViewController { ...@@ -81,25 +80,5 @@ class ViewController: UIViewController {
// Add button to UIViewController. // Add button to UIViewController.
view.addSubview(button) view.addSubview(button)
} }
/// Prepares the FabButton animation example.
private func prepareFabButtonAnimationExample() {
let img: UIImage? = UIImage(named: "ic_create_white")
let button: FabButton = FabButton(frame: CGRectMake(175, 315, 64, 64))
button.setImage(img, forState: .Normal)
button.setImage(img, forState: .Highlighted)
// Add button to UIViewController.
view.addSubview(button)
UIView.animateWithDuration(0.4,
delay: 3,
usingSpringWithDamping: 0.6,
initialSpringVelocity: 0,
options: .AllowUserInteraction,
animations: {
button.frame.origin.x = 300
}, completion: nil)
}
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
965626761C88C218004ADEF7 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 965626751C88C218004ADEF7 /* Material.framework */; };
965626771C88C218004ADEF7 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 965626751C88C218004ADEF7 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96DB1C5F1C14AA2800825BE6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */; }; 96DB1C5F1C14AA2800825BE6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */; };
96DB1C611C14AA2800825BE6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C601C14AA2800825BE6 /* ViewController.swift */; }; 96DB1C611C14AA2800825BE6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C601C14AA2800825BE6 /* ViewController.swift */; };
96DB1C661C14AA2800825BE6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96DB1C651C14AA2800825BE6 /* Assets.xcassets */; }; 96DB1C661C14AA2800825BE6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96DB1C651C14AA2800825BE6 /* Assets.xcassets */; };
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
965626771C88C218004ADEF7 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -27,6 +30,7 @@ ...@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
965626751C88C218004ADEF7 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
96DB1C5B1C14AA2800825BE6 /* MaterialPulseView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialPulseView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 96DB1C5B1C14AA2800825BE6 /* MaterialPulseView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialPulseView.app; sourceTree = BUILT_PRODUCTS_DIR; };
96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96DB1C601C14AA2800825BE6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; 96DB1C601C14AA2800825BE6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
...@@ -40,6 +44,7 @@ ...@@ -40,6 +44,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
965626761C88C218004ADEF7 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
96DB1C521C14AA2800825BE6 = { 96DB1C521C14AA2800825BE6 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
965626751C88C218004ADEF7 /* Material.framework */,
96DB1C5D1C14AA2800825BE6 /* MaterialPulseView */, 96DB1C5D1C14AA2800825BE6 /* MaterialPulseView */,
96DB1C5C1C14AA2800825BE6 /* Products */, 96DB1C5C1C14AA2800825BE6 /* Products */,
); );
......
...@@ -66,6 +66,11 @@ class ViewController: UIViewController { ...@@ -66,6 +66,11 @@ class ViewController: UIViewController {
MaterialAnimation.delay(2) { MaterialAnimation.delay(2) {
pulseView.pulse() pulseView.pulse()
} }
pulseView.animate(MaterialAnimation.animationGroup([
MaterialAnimation.rotate(4.5),
MaterialAnimation.translateY(300)
], duration: 4))
} }
} }
...@@ -57,23 +57,15 @@ class ViewController: UIViewController { ...@@ -57,23 +57,15 @@ class ViewController: UIViewController {
/// Handle the menuView touch event. /// Handle the menuView touch event.
internal func handleMenu() { internal func handleMenu() {
let image: UIImage?
if menuView.menu.opened { if menuView.menu.opened {
menuView.menu.close() menuView.menu.close()
image = UIImage(named: "ic_add_white")?.imageWithRenderingMode(.AlwaysTemplate) (menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(-0.125))
} else { } else {
menuView.menu.open() { (v: UIView) in menuView.menu.open() { (v: UIView) in
(v as? MaterialButton)?.pulse() (v as? MaterialButton)?.pulse()
} }
image = UIImage(named: "ic_close_white")?.imageWithRenderingMode(.AlwaysTemplate) (menuView.menu.views?.first as? MaterialButton)?.animate(MaterialAnimation.rotate(0.125))
} }
// Add a nice rotation animation to the base button.
let first: MaterialButton? = menuView.menu.views?.first as? MaterialButton
first?.animate(MaterialAnimation.rotate(1))
first?.setImage(image, forState: .Normal)
first?.setImage(image, forState: .Highlighted)
} }
/// Handle the menuView touch event. /// Handle the menuView touch event.
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
9656266A1C88242F004ADEF7 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 965626691C88242F004ADEF7 /* Material.framework */; };
9656266B1C88242F004ADEF7 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 965626691C88242F004ADEF7 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96D88C831C132C1800B91418 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88C821C132C1800B91418 /* AppDelegate.swift */; }; 96D88C831C132C1800B91418 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88C821C132C1800B91418 /* AppDelegate.swift */; };
96D88C851C132C1800B91418 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88C841C132C1800B91418 /* ViewController.swift */; }; 96D88C851C132C1800B91418 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88C841C132C1800B91418 /* ViewController.swift */; };
96D88C8A1C132C1800B91418 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96D88C891C132C1800B91418 /* Assets.xcassets */; }; 96D88C8A1C132C1800B91418 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96D88C891C132C1800B91418 /* Assets.xcassets */; };
...@@ -22,7 +20,6 @@ ...@@ -22,7 +20,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
9656266B1C88242F004ADEF7 /* Material.framework in Embed Frameworks */,
); );
name = "Embed Frameworks"; name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -30,7 +27,6 @@ ...@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
965626691C88242F004ADEF7 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-hbpnflxhoouqxebjcyhbbhqyesjd/Build/Products/Debug-iphoneos/Material.framework"; sourceTree = "<absolute>"; };
96D88C7F1C132C1800B91418 /* NavigationBarView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NavigationBarView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 96D88C7F1C132C1800B91418 /* NavigationBarView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NavigationBarView.app; sourceTree = BUILT_PRODUCTS_DIR; };
96D88C821C132C1800B91418 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 96D88C821C132C1800B91418 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96D88C841C132C1800B91418 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; 96D88C841C132C1800B91418 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9656266A1C88242F004ADEF7 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +49,6 @@ ...@@ -54,7 +49,6 @@
96D88C761C132C1800B91418 = { 96D88C761C132C1800B91418 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
965626691C88242F004ADEF7 /* Material.framework */,
96D88C811C132C1800B91418 /* NavigationBarView */, 96D88C811C132C1800B91418 /* NavigationBarView */,
96D88C801C132C1800B91418 /* Products */, 96D88C801C132C1800B91418 /* Products */,
); );
......
...@@ -381,16 +381,19 @@ public class MaterialButton : UIButton { ...@@ -381,16 +381,19 @@ public class MaterialButton : UIButton {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
} }
layer.removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
animationDidStop(x, finished: true) animationDidStop(x, finished: true)
} }
} }
layoutVisualLayer()
} }
/** /**
...@@ -466,7 +469,7 @@ public class MaterialButton : UIButton { ...@@ -466,7 +469,7 @@ public class MaterialButton : UIButton {
internal func layoutVisualLayer() { internal func layoutVisualLayer() {
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2) visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = cornerRadius
} }
/// Manages the layout for the shape of the view instance. /// Manages the layout for the shape of the view instance.
...@@ -479,10 +482,10 @@ public class MaterialButton : UIButton { ...@@ -479,10 +482,10 @@ public class MaterialButton : UIButton {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
layer.shadowPath = nil shadowPath = nil
} else if nil == layer.shadowPath { } else if nil == shadowPath {
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
} }
......
...@@ -434,16 +434,19 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -434,16 +434,19 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
} }
layer.removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
animationDidStop(x, finished: true) animationDidStop(x, finished: true)
} }
} }
layoutVisualLayer()
} }
/** /**
...@@ -520,7 +523,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -520,7 +523,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
internal func layoutVisualLayer() { internal func layoutVisualLayer() {
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2) visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = cornerRadius
} }
/// Manages the layout for the shape of the view instance. /// Manages the layout for the shape of the view instance.
...@@ -533,10 +536,10 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -533,10 +536,10 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
layer.shadowPath = nil shadowPath = nil
} else if nil == layer.shadowPath { } else if nil == shadowPath {
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
} }
......
...@@ -56,12 +56,14 @@ public extension MaterialAnimation { ...@@ -56,12 +56,14 @@ public extension MaterialAnimation {
/** /**
:name: path :name: path
*/ */
public static func path(bezierPath: UIBezierPath, mode: MaterialAnimationRotationMode = .Auto, duration: CFTimeInterval = 0.25) -> CAKeyframeAnimation { public static func path(bezierPath: UIBezierPath, mode: MaterialAnimationRotationMode = .Auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation: CAKeyframeAnimation = CAKeyframeAnimation() let animation: CAKeyframeAnimation = CAKeyframeAnimation()
animation.keyPath = "position" animation.keyPath = "position"
animation.path = bezierPath.CGPath animation.path = bezierPath.CGPath
animation.rotationMode = MaterialAnimationRotationModeToValue(mode) animation.rotationMode = MaterialAnimationRotationModeToValue(mode)
animation.duration = duration if let v: CFTimeInterval = duration {
animation.duration = v
}
return animation return animation
} }
} }
\ No newline at end of file
...@@ -310,16 +310,19 @@ public class MaterialLayer : CAShapeLayer { ...@@ -310,16 +310,19 @@ public class MaterialLayer : CAShapeLayer {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
setValue(v, forKeyPath: k)
removeAnimationForKey(k)
}
}
} }
removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
animationDidStop(x, finished: true) animationDidStop(x, finished: true)
} }
} }
layoutVisualLayer()
} }
/// Prepares the visualLayer property. /// Prepares the visualLayer property.
...@@ -347,7 +350,7 @@ public class MaterialLayer : CAShapeLayer { ...@@ -347,7 +350,7 @@ public class MaterialLayer : CAShapeLayer {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
shadowPath = nil shadowPath = nil
} else if nil == shadowPath { } else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
......
...@@ -336,16 +336,19 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -336,16 +336,19 @@ public class MaterialTableViewCell: UITableViewCell {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
} }
layer.removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
animationDidStop(x, finished: true) animationDidStop(x, finished: true)
} }
} }
layoutVisualLayer()
} }
/** /**
...@@ -426,16 +429,16 @@ public class MaterialTableViewCell: UITableViewCell { ...@@ -426,16 +429,16 @@ public class MaterialTableViewCell: UITableViewCell {
internal func layoutVisualLayer() { internal func layoutVisualLayer() {
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2) visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = cornerRadius
} }
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
layer.shadowPath = nil shadowPath = nil
} else if nil == layer.shadowPath { } else if nil == shadowPath {
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
} }
......
...@@ -83,13 +83,15 @@ public extension MaterialAnimation { ...@@ -83,13 +83,15 @@ public extension MaterialAnimation {
/** /**
:name: transition :name: transition
*/ */
public static func transition(type: MaterialAnimationTransition, direction: MaterialAnimationTransitionSubType? = nil, duration: CFTimeInterval = 0.25) -> CATransition { public static func transition(type: MaterialAnimationTransition, direction: MaterialAnimationTransitionSubType? = nil, duration: CFTimeInterval? = nil) -> CATransition {
let animation: CATransition = CATransition() let animation: CATransition = CATransition()
animation.type = MaterialAnimationTransitionToValue(type) animation.type = MaterialAnimationTransitionToValue(type)
if let d = direction { if let d = direction {
animation.subtype = MaterialAnimationTransitionSubTypeToValue(d) animation.subtype = MaterialAnimationTransitionSubTypeToValue(d)
} }
animation.duration = duration if let v: CFTimeInterval = duration {
animation.duration = v
}
return animation return animation
} }
} }
\ No newline at end of file
...@@ -422,9 +422,13 @@ public class MaterialView : UIView { ...@@ -422,9 +422,13 @@ public class MaterialView : UIView {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
} }
layer.removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
...@@ -457,7 +461,7 @@ public class MaterialView : UIView { ...@@ -457,7 +461,7 @@ public class MaterialView : UIView {
internal func layoutVisualLayer() { internal func layoutVisualLayer() {
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.position = CGPointMake(width / 2, height / 2) visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = cornerRadius
} }
/// Manages the layout for the shape of the view instance. /// Manages the layout for the shape of the view instance.
...@@ -470,10 +474,10 @@ public class MaterialView : UIView { ...@@ -470,10 +474,10 @@ public class MaterialView : UIView {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
layer.shadowPath = nil shadowPath = nil
} else if nil == layer.shadowPath { } else if nil == shadowPath {
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
} }
......
...@@ -35,9 +35,7 @@ public protocol TextFieldDelegate : UITextFieldDelegate {} ...@@ -35,9 +35,7 @@ public protocol TextFieldDelegate : UITextFieldDelegate {}
public class TextField : UITextField { public class TextField : UITextField {
/** /**
This property is the same as clipsToBounds. It crops any of the view's This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using contents from bleeding past the view's frame.
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/ */
public var masksToBounds: Bool { public var masksToBounds: Bool {
get { get {
...@@ -489,9 +487,13 @@ public class TextField : UITextField { ...@@ -489,9 +487,13 @@ public class TextField : UITextField {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
} }
layer.removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
...@@ -579,10 +581,10 @@ public class TextField : UITextField { ...@@ -579,10 +581,10 @@ public class TextField : UITextField {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
layer.shadowPath = nil shadowPath = nil
} else if nil == layer.shadowPath { } else if nil == shadowPath {
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
} }
......
...@@ -37,9 +37,7 @@ public protocol TextViewDelegate : UITextViewDelegate {} ...@@ -37,9 +37,7 @@ public protocol TextViewDelegate : UITextViewDelegate {}
public class TextView: UITextView { public class TextView: UITextView {
/** /**
This property is the same as clipsToBounds. It crops any of the view's This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using contents from bleeding past the view's frame.
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/ */
public var masksToBounds: Bool { public var masksToBounds: Bool {
get { get {
...@@ -434,9 +432,13 @@ public class TextView: UITextView { ...@@ -434,9 +432,13 @@ public class TextView: UITextView {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKeyPath: b.keyPath!) if let v: AnyObject = b.toValue {
if let k: String = b.keyPath {
layer.setValue(v, forKeyPath: k)
layer.removeAnimationForKey(k)
}
}
} }
layer.removeAnimationForKey(a.keyPath!)
(delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag) (delegate as? MaterialAnimationDelegate)?.materialAnimationDidStop?(anim, finished: flag)
} else if let a: CAAnimationGroup = anim as? CAAnimationGroup { } else if let a: CAAnimationGroup = anim as? CAAnimationGroup {
for x in a.animations! { for x in a.animations! {
...@@ -496,10 +498,10 @@ public class TextView: UITextView { ...@@ -496,10 +498,10 @@ public class TextView: UITextView {
/// Sets the shadow path. /// Sets the shadow path.
internal func layoutShadowPath() { internal func layoutShadowPath() {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
if .None == self.depth { if .None == depth {
layer.shadowPath = nil shadowPath = nil
} else if nil == layer.shadowPath { } else if nil == shadowPath {
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
} else { } else {
animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0)) animate(MaterialAnimation.shadowPath(UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath, duration: 0))
} }
......
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