Commit 609842a7 by Daniel Dahan

updated MaterialAnimation with duration management on implicit animations

parent baf52f8b
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
6585D21A1BBCDFBF00426D22 /* BasicCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 964B17D81BBB3911002A9CA0 /* BasicCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 6585D21A1BBCDFBF00426D22 /* BasicCardView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 964B17D81BBB3911002A9CA0 /* BasicCardView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
65AD15EA1BC05B3A0068AF9C /* MaterialLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65AD15E91BC05B3A0068AF9C /* MaterialLayer.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1461BB5B916006F7F2B /* MaterialView.swift */; settings = {ASSET_TAGS = (); }; }; 65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1461BB5B916006F7F2B /* MaterialView.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1481BB5DC98006F7F2B /* MaterialColor.swift */; settings = {ASSET_TAGS = (); }; }; 65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1481BB5DC98006F7F2B /* MaterialColor.swift */; settings = {ASSET_TAGS = (); }; };
65BDD14B1BB5DD02006F7F2B /* MaterialFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD14A1BB5DD02006F7F2B /* MaterialFont.swift */; settings = {ASSET_TAGS = (); }; }; 65BDD14B1BB5DD02006F7F2B /* MaterialFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD14A1BB5DD02006F7F2B /* MaterialFont.swift */; settings = {ASSET_TAGS = (); }; };
...@@ -74,6 +75,7 @@ ...@@ -74,6 +75,7 @@
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
65AD15E91BC05B3A0068AF9C /* MaterialLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialLayer.swift; sourceTree = "<group>"; };
65BDD1461BB5B916006F7F2B /* MaterialView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialView.swift; sourceTree = "<group>"; }; 65BDD1461BB5B916006F7F2B /* MaterialView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialView.swift; sourceTree = "<group>"; };
65BDD1481BB5DC98006F7F2B /* MaterialColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialColor.swift; sourceTree = "<group>"; }; 65BDD1481BB5DC98006F7F2B /* MaterialColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialColor.swift; sourceTree = "<group>"; };
65BDD14A1BB5DD02006F7F2B /* MaterialFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialFont.swift; sourceTree = "<group>"; }; 65BDD14A1BB5DD02006F7F2B /* MaterialFont.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialFont.swift; sourceTree = "<group>"; };
...@@ -130,6 +132,14 @@ ...@@ -130,6 +132,14 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
65AD15E81BC05B0E0068AF9C /* Layer */ = {
isa = PBXGroup;
children = (
65AD15E91BC05B3A0068AF9C /* MaterialLayer.swift */,
);
name = Layer;
sourceTree = "<group>";
};
65B965851B8BEEB00055B139 /* View */ = { 65B965851B8BEEB00055B139 /* View */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -214,6 +224,7 @@ ...@@ -214,6 +224,7 @@
9638325C1B88E3420015F710 /* Supporting Files */, 9638325C1B88E3420015F710 /* Supporting Files */,
96B57D4C1B90AF6A00DE7BBB /* Theme */, 96B57D4C1B90AF6A00DE7BBB /* Theme */,
9AAC38521B89553800FE6B2D /* Font */, 9AAC38521B89553800FE6B2D /* Font */,
65AD15E81BC05B0E0068AF9C /* Layer */,
65B965851B8BEEB00055B139 /* View */, 65B965851B8BEEB00055B139 /* View */,
65BDD16F1BB89A01006F7F2B /* Navigation */, 65BDD16F1BB89A01006F7F2B /* Navigation */,
964B17D71BBB38E2002A9CA0 /* Card */, 964B17D71BBB38E2002A9CA0 /* Card */,
...@@ -430,6 +441,7 @@ ...@@ -430,6 +441,7 @@
65BDD15D1BB70D60006F7F2B /* MaterialInsets.swift in Sources */, 65BDD15D1BB70D60006F7F2B /* MaterialInsets.swift in Sources */,
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */, 65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */,
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */, 65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */,
65AD15EA1BC05B3A0068AF9C /* MaterialLayer.swift in Sources */,
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */, 65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */,
964B17D91BBB3911002A9CA0 /* BasicCardView.swift in Sources */, 964B17D91BBB3911002A9CA0 /* BasicCardView.swift in Sources */,
65BDD1591BB6FE3E006F7F2B /* FlatButton.swift in Sources */, 65BDD1591BB6FE3E006F7F2B /* FlatButton.swift in Sources */,
......
...@@ -371,7 +371,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -371,7 +371,7 @@ public class BasicCardView : MaterialPulseView {
dividerLayer!.backgroundColor = dividerColor?.CGColor dividerLayer!.backgroundColor = dividerColor?.CGColor
dividerLayer!.frame = CGRectMake(0, y, width, 1) dividerLayer!.frame = CGRectMake(0, y, width, 1)
dividerLayer!.zPosition = 900 dividerLayer!.zPosition = 900
visualLayer.addSublayer(dividerLayer!) layer.addSublayer(dividerLayer!)
} }
} }
......
...@@ -45,12 +45,20 @@ public func MaterialAnimationFillModeToValue(mode: MaterialAnimationFillMode) -> ...@@ -45,12 +45,20 @@ public func MaterialAnimationFillModeToValue(mode: MaterialAnimationFillMode) ->
public struct MaterialAnimation { public struct MaterialAnimation {
/** /**
:name: disableAnimation :name: animationDisabled
*/ */
public static func disableAnimation(block: (() -> Void)) { public static func animationDisabled(animations: (() -> Void)) {
animationWithDuration(0, animations: animations)
}
/**
:name: animationWithDuration
*/
public static func animationWithDuration(duration: NSTimeInterval, animations: (() -> Void), completion: (() -> Void)? = nil) {
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0) CATransaction.setAnimationDuration(duration)
block() CATransaction.setCompletionBlock(completion)
animations()
CATransaction.commit() CATransaction.commit()
} }
......
...@@ -19,15 +19,20 @@ ...@@ -19,15 +19,20 @@
import UIKit import UIKit
public class MaterialButton : UIButton { public class MaterialButton : UIButton {
// /**
// :name: visualLayer :name: spotlight
// */
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer() public lazy var spotlight: Bool = false
// /**
// :name: pulseLayer :name: visualLayer
// */
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var visualLayer: MaterialLayer = MaterialLayer()
/**
:name: pulseLayer
*/
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/** /**
:name: pulseColorOpacity :name: pulseColorOpacity
...@@ -272,7 +277,7 @@ public class MaterialButton : UIButton { ...@@ -272,7 +277,7 @@ public class MaterialButton : UIButton {
:name: layerClass :name: layerClass
*/ */
public override class func layerClass() -> AnyClass { public override class func layerClass() -> AnyClass {
return CAShapeLayer.self return MaterialLayer.self
} }
/** /**
...@@ -357,14 +362,38 @@ public class MaterialButton : UIButton { ...@@ -357,14 +362,38 @@ public class MaterialButton : UIButton {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer) let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) { if true == layer.containsPoint(point) {
let s: CGFloat = (width < height ? height : width) / 2 let s: CGFloat = (width < height ? height : width) / 2
MaterialAnimation.disableAnimation({ let f: CGFloat = 3
self.pulseLayer.bounds = CGRectMake(0, 0, s, s) var v: CGFloat = s / f
MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
self.pulseLayer.position = point self.pulseLayer.position = point
self.pulseLayer.cornerRadius = s / 2 self.pulseLayer.cornerRadius = s / 6
})
v = 2 * f
MaterialAnimation.animationWithDuration(0.4, animations: {
self.pulseLayer.transform = CATransform3DMakeScale(v, v, v)
})
MaterialAnimation.animationWithDuration(0.25, animations: {
self.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
}) })
pulseLayer.hidden = false }
pulseLayer.transform = CATransform3DMakeScale(3, 3, 3) }
layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
/**
:name: touchesMoved
*/
public override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesMoved(touches, withEvent: event)
if spotlight {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) {
MaterialAnimation.animationDisabled({
self.pulseLayer.position = point
})
}
} }
} }
...@@ -425,8 +454,10 @@ public class MaterialButton : UIButton { ...@@ -425,8 +454,10 @@ public class MaterialButton : UIButton {
// :name: shrink // :name: shrink
// //
internal func shrink() { internal func shrink() {
pulseLayer.hidden = true MaterialAnimation.animationWithDuration(0.25, animations: {
pulseLayer.transform = CATransform3DIdentity self.pulseLayer.hidden = true
layer.transform = CATransform3DIdentity self.pulseLayer.transform = CATransform3DIdentity
self.layer.transform = CATransform3DIdentity
})
} }
} }
\ No newline at end of file
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
import UIKit
public class MaterialLayer : CAShapeLayer {
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public override init(layer: AnyObject) {
super.init(layer: layer)
}
public override init() {
super.init()
}
}
...@@ -19,10 +19,15 @@ ...@@ -19,10 +19,15 @@
import UIKit import UIKit
public class MaterialPulseView : MaterialView { public class MaterialPulseView : MaterialView {
// /**
// :name: pulseLayer :name: spotlight
// */
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer() public lazy var spotlight: Bool = false
/**
:name: pulseLayer
*/
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/** /**
:name: pulseColorOpacity :name: pulseColorOpacity
...@@ -52,14 +57,38 @@ public class MaterialPulseView : MaterialView { ...@@ -52,14 +57,38 @@ public class MaterialPulseView : MaterialView {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer) let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) { if true == layer.containsPoint(point) {
let s: CGFloat = (width < height ? height : width) / 2 let s: CGFloat = (width < height ? height : width) / 2
MaterialAnimation.disableAnimation({ let f: CGFloat = 3
self.pulseLayer.bounds = CGRectMake(0, 0, s, s) var v: CGFloat = s / f
MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
self.pulseLayer.position = point self.pulseLayer.position = point
self.pulseLayer.cornerRadius = s / 2 self.pulseLayer.cornerRadius = s / 6
})
v = 2 * f
MaterialAnimation.animationWithDuration(0.4, animations: {
self.pulseLayer.transform = CATransform3DMakeScale(v, v, v)
})
MaterialAnimation.animationWithDuration(0.25, animations: {
self.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
}) })
pulseLayer.hidden = false }
pulseLayer.transform = CATransform3DMakeScale(3, 3, 3) }
layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
/**
:name: touchesMoved
*/
public override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesMoved(touches, withEvent: event)
if spotlight {
let point: CGPoint = layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if true == layer.containsPoint(point) {
MaterialAnimation.animationDisabled({
self.pulseLayer.position = point
})
}
} }
} }
...@@ -125,8 +154,10 @@ public class MaterialPulseView : MaterialView { ...@@ -125,8 +154,10 @@ public class MaterialPulseView : MaterialView {
// :name: shrink // :name: shrink
// //
internal func shrink() { internal func shrink() {
pulseLayer.hidden = true MaterialAnimation.animationWithDuration(0.25, animations: {
pulseLayer.transform = CATransform3DIdentity self.pulseLayer.hidden = true
layer.transform = CATransform3DIdentity self.pulseLayer.transform = CATransform3DIdentity
self.layer.transform = CATransform3DIdentity
})
} }
} }
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