Commit b1ac229d by Daniel Dahan

updates to internal layout for MaterialTextView

parent e10b5f39
...@@ -300,7 +300,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -300,7 +300,7 @@ public class BasicCardView : MaterialPulseView {
verticalFormat += "-[titleLabel]" verticalFormat += "-[titleLabel]"
views["titleLabel"] = v views["titleLabel"] = v
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
} }
// detail // detail
...@@ -317,7 +317,7 @@ public class BasicCardView : MaterialPulseView { ...@@ -317,7 +317,7 @@ public class BasicCardView : MaterialPulseView {
verticalFormat += "-[detailLabel]" verticalFormat += "-[detailLabel]"
views["detailLabel"] = v views["detailLabel"] = v
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
} }
// leftButtons // leftButtons
......
...@@ -400,7 +400,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -400,7 +400,7 @@ public class ImageCardView : MaterialPulseView {
} else { } else {
MaterialLayout.alignFromTop(self, child: v, top: contentInsetsRef.top + titleLabelInsetsRef.top) MaterialLayout.alignFromTop(self, child: v, top: contentInsetsRef.top + titleLabelInsetsRef.top)
} }
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
} }
// detail // detail
...@@ -417,7 +417,7 @@ public class ImageCardView : MaterialPulseView { ...@@ -417,7 +417,7 @@ public class ImageCardView : MaterialPulseView {
verticalFormat += "-[detailLabel]" verticalFormat += "-[detailLabel]"
views["detailLabel"] = v views["detailLabel"] = v
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
} }
// leftButtons // leftButtons
......
...@@ -46,48 +46,25 @@ public struct MaterialLayout { ...@@ -46,48 +46,25 @@ public struct MaterialLayout {
} }
/** /**
:name: alignToParent
*/
public static func alignToParent(parent: UIView, child: UIView) {
let views: Dictionary<String, AnyObject> = ["child" : child]
parent.addConstraints(constraint("H:|[child]|", options: [], metrics: nil, views: views))
parent.addConstraints(constraint("V:|[child]|", options: [], metrics: nil, views: views))
}
/**
:name: alignToParentHorizontally
*/
public static func alignToParentHorizontally(parent: UIView, child: UIView) {
alignToParentHorizontallyWithInsets(parent, child: child, left: 0, right: 0)
}
/**
:name: alignToParentHorizontallyWithInsets :name: alignToParentHorizontallyWithInsets
*/ */
public static func alignToParentHorizontallyWithInsets(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0) { public static func alignToParentHorizontally(parent: UIView, child: UIView, left: CGFloat = 0, right: CGFloat = 0) {
parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: [], metrics: ["left": left, "right": right], views: ["child" : child])) parent.addConstraints(constraint("H:|-(left)-[child]-(right)-|", options: [], metrics: ["left": left, "right": right], views: ["child" : child]))
} }
/** /**
:name: alignToParentVertically :name: alignToParentVertically
*/ */
public static func alignToParentVertically(parent: UIView, child: UIView) { public static func alignToParentVertically(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0) {
alignToParentVerticallyWithInsets(parent, child: child, top: 0, bottom: 0)
}
/**
:name: alignToParentVerticallyWithInsets
*/
public static func alignToParentVerticallyWithInsets(parent: UIView, child: UIView, top: CGFloat = 0, bottom: CGFloat = 0) {
parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: [], metrics: ["bottom": bottom, "top": top], views: ["child" : child])) parent.addConstraints(constraint("V:|-(top)-[child]-(bottom)-|", options: [], metrics: ["bottom": bottom, "top": top], views: ["child" : child]))
} }
/** /**
:name: alignToParentWithInsets :name: alignToParent
*/ */
public static func alignToParentWithInsets(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) { public static func alignToParent(parent: UIView, child: UIView, top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0) {
alignToParentHorizontallyWithInsets(parent, child: child, left: left, right: right) alignToParentHorizontally(parent, child: child, left: left, right: right)
alignToParentVerticallyWithInsets(parent, child: child, top: top, bottom: bottom) alignToParentVertically(parent, child: child, top: top, bottom: bottom)
} }
/** /**
......
...@@ -469,7 +469,7 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -469,7 +469,7 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
// :name: layoutVisualLayer // :name: layoutVisualLayer
// //
internal func layoutVisualLayer() { internal func layoutVisualLayer() {
visualLayer.frame = bounds visualLayer.bounds = bounds
visualLayer.position = CGPointMake(width / 2, height / 2) visualLayer.position = CGPointMake(width / 2, height / 2)
visualLayer.cornerRadius = layer.cornerRadius visualLayer.cornerRadius = layer.cornerRadius
} }
......
...@@ -21,11 +21,6 @@ import UIKit ...@@ -21,11 +21,6 @@ import UIKit
public protocol MaterialTextViewDelegate : UITextViewDelegate {} public protocol MaterialTextViewDelegate : UITextViewDelegate {}
public class MaterialTextView: UITextView { public class MaterialTextView: UITextView {
//
// :name: layoutConstraints
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
/** /**
:name: init :name: init
*/ */
...@@ -105,26 +100,9 @@ public class MaterialTextView: UITextView { ...@@ -105,26 +100,9 @@ public class MaterialTextView: UITextView {
*/ */
internal func updateLabelConstraints() { internal func updateLabelConstraints() {
if let p = placeholderLabel { if let p = placeholderLabel {
NSLayoutConstraint.deactivateConstraints(layoutConstraints) removeConstraints(constraints)
layoutConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-(left)-[placeholderLabel]-(right)-|", MaterialLayout.alignToParentHorizontally(self, child: p, left: textContainerInset.left + textContainer.lineFragmentPadding, right: textContainerInset.right + textContainer.lineFragmentPadding)
options: [], MaterialLayout.alignToParentVertically(self, child: p, top: textContainerInset.top, bottom: textContainerInset.bottom)
metrics: [
"left": textContainerInset.left + textContainer.lineFragmentPadding,
"right": textContainerInset.right + textContainer.lineFragmentPadding
], views: [
"placeholderLabel": p
])
layoutConstraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-(top)-[placeholderLabel]-(>=bottom)-|",
options: [],
metrics: [
"top": textContainerInset.top,
"bottom": textContainerInset.bottom
],
views: [
"placeholderLabel": p
])
NSLayoutConstraint.activateConstraints(layoutConstraints)
} }
} }
...@@ -141,10 +119,10 @@ public class MaterialTextView: UITextView { ...@@ -141,10 +119,10 @@ public class MaterialTextView: UITextView {
// :name: prepareView // :name: prepareView
// //
private func prepareView() { private func prepareView() {
// label needs to be added to the view
// hierarchy before setting insets
textContainerInset = UIEdgeInsetsMake(16, 16, 16, 16) textContainerInset = UIEdgeInsetsMake(16, 16, 16, 16)
backgroundColor = .clearColor() backgroundColor = MaterialColor.clear
NSNotificationCenter.defaultCenter().removeObserver(self)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextViewTextDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "textViewTextDidChange", name: UITextViewTextDidChangeNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "textViewTextDidChange", name: UITextViewTextDidChangeNotification, object: nil)
updateLabelConstraints() updateLabelConstraints()
} }
......
...@@ -242,7 +242,7 @@ public class NavigationBarView : MaterialView { ...@@ -242,7 +242,7 @@ public class NavigationBarView : MaterialView {
views["titleLabel"] = v views["titleLabel"] = v
addSubview(v) addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + titleLabelInsetsRef.left, right: contentInsetsRef.right + titleLabelInsetsRef.right)
} }
// detail // detail
...@@ -256,7 +256,7 @@ public class NavigationBarView : MaterialView { ...@@ -256,7 +256,7 @@ public class NavigationBarView : MaterialView {
views["detailLabel"] = v views["detailLabel"] = v
addSubview(v) addSubview(v)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: v, left: contentInsetsRef.left + detailLabelInsetsRef.left, right: contentInsetsRef.right + detailLabelInsetsRef.right)
} }
// leftButtons // leftButtons
......
...@@ -224,7 +224,7 @@ public class SearchBarView : MaterialView, UITextFieldDelegate { ...@@ -224,7 +224,7 @@ public class SearchBarView : MaterialView, UITextFieldDelegate {
addSubview(textField) addSubview(textField)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: textField, left: contentInsetsRef.left + textFieldInsetsRef.left, right: contentInsetsRef.right + textFieldInsetsRef.right) MaterialLayout.alignToParentHorizontally(self, child: textField, left: contentInsetsRef.left + textFieldInsetsRef.left, right: contentInsetsRef.right + textFieldInsetsRef.right)
// leftButtons // leftButtons
if let v = leftButtons { if let v = leftButtons {
......
...@@ -192,8 +192,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -192,8 +192,12 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
let w: CGFloat = (hidden ? -width : width) / 2 let w: CGFloat = (hidden ? -width : width) / 2
if animated { if animated {
self.leftView!.width = width MaterialAnimation.animationWithDuration(0.25, animations: {
self.leftView!.position.x = w self.leftView!.width = width
self.leftView!.position.x = w
}) {
self.userInteractionEnabled = false
}
} else { } else {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled({
self.leftView!.width = width self.leftView!.width = width
...@@ -213,14 +217,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -213,14 +217,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: openLeftViewContainer :name: openLeftViewContainer
*/ */
public func openLeftViewContainer(velocity: CGFloat = 0) { public func openLeftViewContainer(velocity: CGFloat = 0) {
if let vc = leftView { if let v = leftView {
let w: CGFloat = vc.width let w: CGFloat = v.width
let h: CGFloat = vc.height let h: CGFloat = v.height
let d: Double = Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(vc.x / velocity)))) let d: Double = Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity))))
toggleStatusBar(true) toggleStatusBar(true)
MaterialAnimation.animationWithDuration(d, animations: { MaterialAnimation.animationWithDuration(d, animations: {
vc.position = CGPointMake(w / 2, h / 2) v.position = CGPointMake(w / 2, h / 2)
self.backdropLayer.hidden = false self.backdropLayer.hidden = false
}) { }) {
self.userInteractionEnabled = false self.userInteractionEnabled = false
...@@ -232,14 +236,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -232,14 +236,14 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
:name: closeLeftViewContainer :name: closeLeftViewContainer
*/ */
public func closeLeftViewContainer(velocity: CGFloat = 0) { public func closeLeftViewContainer(velocity: CGFloat = 0) {
if let vc = leftView { if let v = leftView {
let w: CGFloat = vc.width let w: CGFloat = v.width
let h: CGFloat = vc.height let h: CGFloat = v.height
let d: Double = Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(vc.x / velocity)))) let d: Double = Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity))))
toggleStatusBar(false) toggleStatusBar(false)
MaterialAnimation.animationWithDuration(d, animations: { MaterialAnimation.animationWithDuration(d, animations: {
vc.position = CGPointMake(-w / 2, h / 2) v.position = CGPointMake(-w / 2, h / 2)
self.backdropLayer.hidden = true self.backdropLayer.hidden = true
}) { }) {
self.userInteractionEnabled = true self.userInteractionEnabled = true
...@@ -435,7 +439,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -435,7 +439,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareViewControllerWithinContainer // :name: prepareViewControllerWithinContainer
// //
private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) { private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) {
controller.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] controller.view.clipsToBounds = true
addChildViewController(controller) addChildViewController(controller)
container.addSubview(controller.view) container.addSubview(controller.view)
controller.didMoveToParentViewController(self) controller.didMoveToParentViewController(self)
......
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