Commit a5d3a705 by Daniel Dahan

added visualLayer

parent edfbcb3f
......@@ -32,6 +32,8 @@
65BDD16A1BB7146B006F7F2B /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1691BB7146B006F7F2B /* MaterialBorder.swift */; settings = {ASSET_TAGS = (); }; };
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD16B1BB88D1A006F7F2B /* MaterialShape.swift */; settings = {ASSET_TAGS = (); }; };
65BDD16E1BB899F2006F7F2B /* MaterialPulseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD16D1BB899F2006F7F2B /* MaterialPulseView.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1711BB8CD77006F7F2B /* MaterialLabel.swift */; settings = {ASSET_TAGS = (); }; };
65BDD1741BB8D443006F7F2B /* MaterialAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1731BB8D443006F7F2B /* MaterialAnimation.swift */; settings = {ASSET_TAGS = (); }; };
65DBE4201B9A9244000C804F /* Roboto-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */; };
65DBE4211B9A9244000C804F /* Roboto-Thin.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */; };
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; };
......@@ -69,6 +71,8 @@
65BDD1691BB7146B006F7F2B /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; };
65BDD16B1BB88D1A006F7F2B /* MaterialShape.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialShape.swift; sourceTree = "<group>"; };
65BDD16D1BB899F2006F7F2B /* MaterialPulseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialPulseView.swift; sourceTree = "<group>"; };
65BDD1711BB8CD77006F7F2B /* MaterialLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialLabel.swift; sourceTree = "<group>"; };
65BDD1731BB8D443006F7F2B /* MaterialAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialAnimation.swift; sourceTree = "<group>"; };
65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Bold.ttf"; sourceTree = "<group>"; };
65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Thin.ttf"; sourceTree = "<group>"; };
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBarView.swift; sourceTree = "<group>"; };
......@@ -141,6 +145,22 @@
name = Navigation;
sourceTree = "<group>";
};
65BDD1701BB8CD56006F7F2B /* Label */ = {
isa = PBXGroup;
children = (
65BDD1711BB8CD77006F7F2B /* MaterialLabel.swift */,
);
name = Label;
sourceTree = "<group>";
};
65BDD1751BB8D44B006F7F2B /* Animation */ = {
isa = PBXGroup;
children = (
65BDD1731BB8D443006F7F2B /* MaterialAnimation.swift */,
);
name = Animation;
sourceTree = "<group>";
};
9638322C1B88DFD80015F710 = {
isa = PBXGroup;
children = (
......@@ -168,7 +188,9 @@
9AAC38521B89553800FE6B2D /* Font */,
65B965851B8BEEB00055B139 /* View */,
65BDD16F1BB89A01006F7F2B /* Navigation */,
65BDD1701BB8CD56006F7F2B /* Label */,
65BDD1551BB6FC60006F7F2B /* Button */,
65BDD1751BB8D44B006F7F2B /* Animation */,
);
path = Source;
sourceTree = "<group>";
......@@ -358,9 +380,11 @@
65BDD1541BB6F473006F7F2B /* MaterialShadow.swift in Sources */,
65BDD1571BB6FC82006F7F2B /* MaterialButton.swift in Sources */,
65BDD16E1BB899F2006F7F2B /* MaterialPulseView.swift in Sources */,
65BDD1741BB8D443006F7F2B /* MaterialAnimation.swift in Sources */,
65BDD14B1BB5DD02006F7F2B /* MaterialFont.swift in Sources */,
65BDD16A1BB7146B006F7F2B /* MaterialBorder.swift in Sources */,
65BDD15B1BB7095E006F7F2B /* MaterialRadius.swift in Sources */,
65BDD1721BB8CD77006F7F2B /* MaterialLabel.swift in Sources */,
65BDD1491BB5DC98006F7F2B /* MaterialColor.swift in Sources */,
65BDD14D1BB5ED9F006F7F2B /* MaterialTheme.swift in Sources */,
);
......
//
// 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 struct MaterialAnimation {
/**
:name: rotate
*/
public static func rotate(layer: CALayer, duration: CFTimeInterval, completion: (() -> Void)? = nil) {
CATransaction.begin()
CATransaction.setAnimationDuration(duration)
let transform: CGAffineTransform = CGAffineTransformRotate(layer.affineTransform(), CGFloat(M_PI))
layer.setAffineTransform(transform)
CATransaction.setCompletionBlock(completion)
CATransaction.commit()
}
/**
:name: pulse
*/
public static func pulse(layer: CALayer, duraction: CFTimeInterval, completion: (() -> Void)? = nil) {
CATransaction.begin()
CATransaction.setAnimationDuration(1.0)
CATransaction.commit()
}
}
//
// 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 MaterialLabel : UILabel {
/**
:name: layerClass
*/
public override class func layerClass() -> AnyClass {
return CATextLayer.self
}
}
\ No newline at end of file
......@@ -73,7 +73,7 @@ public class MaterialPulseView: MaterialView {
//
// :name: pulseLayer
//
internal lazy var pulseLayer: CALayer = CALayer()
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/**
:name: init
......@@ -87,7 +87,11 @@ public class MaterialPulseView: MaterialView {
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
layer.addSublayer(pulseLayer)
// pulseLayer.hidden = false
// let point: CGPoint = touches.first!.locationInView(self)
// let pulse: CAShapeLayer = CAShapeLayer()
// pulse.bounds = CGRectMake(point.x, point.y, 0, 0)
// pulse.backgroundColor = MaterialColor.white.CGColor
}
/**
......@@ -95,7 +99,8 @@ public class MaterialPulseView: MaterialView {
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
pulseLayer.removeFromSuperlayer()
// pulseLayer.hidden = true
MaterialAnimation.rotate(visualLayer, duration: 1)
}
/**
......@@ -134,7 +139,9 @@ public class MaterialPulseView: MaterialView {
// pulseLayer
pulseLayer.frame = CGRectMake(0, 0, width, height)
pulseLayer.masksToBounds = true
pulseLayer.backgroundColor = MaterialColor.blue.accent3.CGColor
pulseLayer.hidden = true
pulseLayer.backgroundColor = MaterialColor.red.base.CGColor
visualLayer.addSublayer(pulseLayer)
}
//
......
......@@ -19,12 +19,17 @@
import UIKit
public class MaterialView: UIView {
//
// :name: visualLayer
//
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
:name: image
*/
public var image: UIImage? {
didSet {
layer.contents = image?.CGImage
visualLayer.contents = image?.CGImage
}
}
......@@ -33,7 +38,7 @@ public class MaterialView: UIView {
*/
public var contentsRect: CGRect! {
didSet {
layer.contentsRect = contentsRect
visualLayer.contentsRect = contentsRect
}
}
......@@ -42,7 +47,7 @@ public class MaterialView: UIView {
*/
public var contentsCenter: CGRect! {
didSet {
layer.contentsCenter = contentsCenter
visualLayer.contentsCenter = contentsCenter
}
}
......@@ -51,7 +56,7 @@ public class MaterialView: UIView {
*/
public var contentsScale: CGFloat! {
didSet {
layer.contentsScale = contentsScale
visualLayer.contentsScale = contentsScale
}
}
......@@ -60,7 +65,7 @@ public class MaterialView: UIView {
*/
public var contentsGravity: MaterialGravity! {
didSet {
layer.contentsGravity = MaterialGravityToString(contentsGravity)
visualLayer.contentsGravity = MaterialGravityToString(contentsGravity)
}
}
......@@ -69,10 +74,10 @@ public class MaterialView: UIView {
*/
public override var backgroundColor: UIColor? {
get {
return nil == layer.backgroundColor ? nil : UIColor(CGColor: layer.backgroundColor!)
return nil == visualLayer.backgroundColor ? nil : UIColor(CGColor: visualLayer.backgroundColor!)
}
set(value) {
layer.backgroundColor = value?.CGColor
visualLayer.backgroundColor = value?.CGColor
}
}
......@@ -109,6 +114,7 @@ public class MaterialView: UIView {
}
set(value) {
layer.frame.size.width = value
visualLayer.frame.size.width = value
prepareShape()
}
}
......@@ -122,6 +128,7 @@ public class MaterialView: UIView {
}
set(value) {
layer.frame.size.height = value
visualLayer.frame.size.height = value
prepareShape()
}
}
......@@ -167,7 +174,7 @@ public class MaterialView: UIView {
*/
public var masksToBounds: Bool! {
didSet {
layer.masksToBounds = masksToBounds
visualLayer.masksToBounds = masksToBounds
}
}
......@@ -176,7 +183,7 @@ public class MaterialView: UIView {
*/
public var cornerRadius: MaterialRadius! {
didSet {
layer.cornerRadius = MaterialRadiusToValue(cornerRadius!)
visualLayer.cornerRadius = MaterialRadiusToValue(cornerRadius!)
}
}
......@@ -194,7 +201,7 @@ public class MaterialView: UIView {
*/
public var borderWidth: MaterialBorder! {
didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth!)
visualLayer.borderWidth = MaterialBorderToValue(borderWidth!)
}
}
......@@ -203,7 +210,7 @@ public class MaterialView: UIView {
*/
public var borderColor: UIColor! {
didSet {
layer.borderColor = borderColor.CGColor
visualLayer.borderColor = borderColor.CGColor
}
}
......@@ -251,6 +258,13 @@ public class MaterialView: UIView {
self.init(frame: CGRectMake(MaterialTheme.view.x, MaterialTheme.view.y, MaterialTheme.view.width, MaterialTheme.view.height))
}
/**
:name: layerClass
*/
public override class func layerClass() -> AnyClass {
return CAShapeLayer.self
}
//
// :name: prepareView
//
......@@ -274,6 +288,10 @@ public class MaterialView: UIView {
cornerRadius = MaterialTheme.view.cornerRadius
borderWidth = MaterialTheme.view.borderWidth
borderColor = MaterialTheme.view.bordercolor
// visualLayer
visualLayer.frame = CGRectMake(0, 0, width, height)
layer.addSublayer(visualLayer)
}
//
......@@ -283,10 +301,13 @@ public class MaterialView: UIView {
if nil != shape {
if width < height {
layer.frame.size.width = height
visualLayer.frame.size.width = height
} else {
layer.frame.size.height = width
visualLayer.frame.size.height = width
}
layer.cornerRadius = .Square == shape ? 0 : width / 2
layer.cornerRadius = .Square == shape ? 0 : layer.frame.size.width / 2
visualLayer.cornerRadius = layer.cornerRadius
}
}
}
......
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