Commit b1ac229d by Daniel Dahan

updates to internal layout for MaterialTextView

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