Commit a6dd917a by Daniel Dahan

updated MaterialLayout internals

parent 2adcab8e
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'MK' s.name = 'MK'
s.version = '1.17.1' s.version = '1.17.2'
s.license = { :type => "AGPLv3+", :file => "LICENSE" } s.license = { :type => "AGPLv3+", :file => "LICENSE" }
s.summary = 'A Material Design Framework In Swift' s.summary = 'A Material Design Framework In Swift'
s.homepage = 'http://materialkit.io' s.homepage = 'http://materialkit.io'
......
...@@ -24,9 +24,6 @@ public class FabButton : MaterialButton { ...@@ -24,9 +24,6 @@ public class FabButton : MaterialButton {
*/ */
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if false == translatesAutoresizingMaskIntoConstraints {
prepareShape()
}
} }
// //
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.17.1</string> <string>1.17.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -100,7 +100,6 @@ public class MaterialButton : UIButton { ...@@ -100,7 +100,6 @@ public class MaterialButton : UIButton {
frame.size.width = value frame.size.width = value
if nil != shape { if nil != shape {
frame.size.height = value frame.size.height = value
prepareShape()
} }
} }
} }
...@@ -116,7 +115,6 @@ public class MaterialButton : UIButton { ...@@ -116,7 +115,6 @@ public class MaterialButton : UIButton {
frame.size.height = value frame.size.height = value
if nil != shape { if nil != shape {
frame.size.width = value frame.size.width = value
prepareShape()
} }
} }
} }
...@@ -172,9 +170,11 @@ public class MaterialButton : UIButton { ...@@ -172,9 +170,11 @@ public class MaterialButton : UIButton {
public var cornerRadius: MaterialRadius! { public var cornerRadius: MaterialRadius! {
didSet { didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!) layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!)
if .Circle == shape {
shape = nil shape = nil
} }
} }
}
/** /**
:name: shape :name: shape
...@@ -187,7 +187,6 @@ public class MaterialButton : UIButton { ...@@ -187,7 +187,6 @@ public class MaterialButton : UIButton {
} else { } else {
frame.size.height = width frame.size.height = width
} }
prepareShape()
} }
} }
} }
...@@ -274,6 +273,8 @@ public class MaterialButton : UIButton { ...@@ -274,6 +273,8 @@ public class MaterialButton : UIButton {
*/ */
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
prepareShape()
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = layer.cornerRadius
...@@ -291,7 +292,7 @@ public class MaterialButton : UIButton { ...@@ -291,7 +292,7 @@ public class MaterialButton : UIButton {
// set start position // set start position
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0) CATransaction.setAnimationDuration(0)
let w: CGFloat = width / 2 let w: CGFloat = (width < height ? height : width) / 2
pulseLayer.hidden = false pulseLayer.hidden = false
pulseLayer.position = point pulseLayer.position = point
pulseLayer.bounds = CGRectMake(0, 0, w, w) pulseLayer.bounds = CGRectMake(0, 0, w, w)
...@@ -351,7 +352,9 @@ public class MaterialButton : UIButton { ...@@ -351,7 +352,9 @@ public class MaterialButton : UIButton {
// :name: prepareShape // :name: prepareShape
// //
internal func prepareShape() { internal func prepareShape() {
layer.cornerRadius = .Square == shape ? 0 : width / 2 if .Circle == shape {
layer.cornerRadius = width / 2
}
} }
// //
......
...@@ -86,49 +86,40 @@ public struct MaterialLayout { ...@@ -86,49 +86,40 @@ public struct MaterialLayout {
:name: alignToParentWithInsets :name: alignToParentWithInsets
*/ */
public static func alignToParentWithInsets(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) { public static func alignToParentWithInsets(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) {
let views: Dictionary<String, AnyObject> = ["child" : child] alignToParentHorizontallyWithInsets(parent, child: child, left: left, right: right)
parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: [], metrics: ["left": left, "right": right], views: views)) alignToParentVerticallyWithInsets(parent, child: child, top: top, bottom: bottom)
parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: [], metrics: ["bottom": bottom, "top": top], views: views))
} }
/** /**
:name: alignFromTopLeft :name: alignFromTopLeft
*/ */
public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0) { public static func alignFromTopLeft(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "left" : left] alignFromTop(parent, child: child, top: top)
let views: Dictionary<String, AnyObject> = ["child" : child] alignFromLeft(parent, child: child, left: left)
parent.addConstraints(constraint("H:|-(left)-[child]", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:|-(top)-[child]", options: [], metrics: metrics, views: views))
} }
/** /**
:name: alignFromTopRight :name: alignFromTopRight
*/ */
public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat = 0, right: CGFloat = 0) { public static func alignFromTopRight(parent: UIView, child: UIView, top: CGFloat = 0, right: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["top" : top, "right" : right] alignFromTop(parent, child: child, top: top)
let views: Dictionary<String, AnyObject> = ["child" : child] alignFromRight(parent, child: child, right: right)
parent.addConstraints(constraint("H:[child]-(right)-|", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:|-(top)-[child]", options: [], metrics: metrics, views: views))
} }
/** /**
:name: alignFromBottomLeft :name: alignFromBottomLeft
*/ */
public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat = 0, left: CGFloat = 0) { public static func alignFromBottomLeft(parent: UIView, child: UIView, bottom: CGFloat = 0, left: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "left" : left] alignFromBottom(parent, child: child, bottom: bottom)
let views: Dictionary<String, AnyObject> = ["child" : child] alignFromLeft(parent, child: child, left: left)
parent.addConstraints(constraint("H:|-(left)-[child]", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: [], metrics: metrics, views: views))
} }
/** /**
:name: alignFromBottomRight :name: alignFromBottomRight
*/ */
public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat = 0, right: CGFloat = 0) { public static func alignFromBottomRight(parent: UIView, child: UIView, bottom: CGFloat = 0, right: CGFloat = 0) {
let metrics: Dictionary<String, AnyObject> = ["bottom" : bottom, "right" : right] alignFromBottom(parent, child: child, bottom: bottom)
let views: Dictionary<String, AnyObject> = ["child" : child] alignFromRight(parent, child: child, right: right)
parent.addConstraints(constraint("H:[child]-(right)-|", options: [], metrics: metrics, views: views))
parent.addConstraints(constraint("V:[child]-(bottom)-|", options: [], metrics: metrics, views: views))
} }
/** /**
......
...@@ -75,7 +75,7 @@ public class MaterialPulseView: MaterialView { ...@@ -75,7 +75,7 @@ public class MaterialPulseView: MaterialView {
// set start position // set start position
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0) CATransaction.setAnimationDuration(0)
let w: CGFloat = width / 2 let w: CGFloat = (width < height ? height : width) / 2
pulseLayer.hidden = false pulseLayer.hidden = false
pulseLayer.position = point pulseLayer.position = point
pulseLayer.bounds = CGRectMake(0, 0, w, w) pulseLayer.bounds = CGRectMake(0, 0, w, w)
......
...@@ -116,7 +116,6 @@ public class MaterialView: UIView { ...@@ -116,7 +116,6 @@ public class MaterialView: UIView {
frame.size.width = value frame.size.width = value
if nil != shape { if nil != shape {
frame.size.height = value frame.size.height = value
prepareShape()
} }
} }
} }
...@@ -132,7 +131,6 @@ public class MaterialView: UIView { ...@@ -132,7 +131,6 @@ public class MaterialView: UIView {
frame.size.height = value frame.size.height = value
if nil != shape { if nil != shape {
frame.size.width = value frame.size.width = value
prepareShape()
} }
} }
} }
...@@ -188,9 +186,11 @@ public class MaterialView: UIView { ...@@ -188,9 +186,11 @@ public class MaterialView: UIView {
public var cornerRadius: MaterialRadius! { public var cornerRadius: MaterialRadius! {
didSet { didSet {
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!) layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .None : cornerRadius!)
if .Circle == shape {
shape = nil shape = nil
} }
} }
}
/** /**
:name: shape :name: shape
...@@ -203,7 +203,6 @@ public class MaterialView: UIView { ...@@ -203,7 +203,6 @@ public class MaterialView: UIView {
} else { } else {
frame.size.height = width frame.size.height = width
} }
prepareShape()
} }
} }
} }
...@@ -281,6 +280,8 @@ public class MaterialView: UIView { ...@@ -281,6 +280,8 @@ public class MaterialView: UIView {
*/ */
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
prepareShape()
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = layer.cornerRadius
} }
...@@ -313,7 +314,9 @@ public class MaterialView: UIView { ...@@ -313,7 +314,9 @@ public class MaterialView: UIView {
// :name: prepareShape // :name: prepareShape
// //
internal func prepareShape() { internal func prepareShape() {
layer.cornerRadius = .Square == shape ? 0 : width / 2 if .Circle == shape {
layer.cornerRadius = width / 2
}
} }
} }
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