Commit 44b579be by Daniel Dahan

updating SideNavigationViewController API and animations

parent 654641a9
......@@ -20,14 +20,7 @@ import UIKit
@objc(MaterialAnimationDelegate)
public protocol MaterialAnimationDelegate : MaterialDelegate {
/**
:name: materialAnimationDidStart
*/
optional func materialAnimationDidStart(animation: CAAnimation)
/**
:name: materialAnimationDidStop
*/
optional func materialAnimationDidStop(animation: CAAnimation, finished flag: Bool)
}
......
......@@ -106,10 +106,10 @@ public class MaterialButton : UIButton {
*/
public var x: CGFloat {
get {
return frame.origin.x
return layer.frame.origin.x
}
set(value) {
frame.origin.x = value
layer.frame.origin.x = value
}
}
......@@ -118,10 +118,10 @@ public class MaterialButton : UIButton {
*/
public var y: CGFloat {
get {
return frame.origin.y
return layer.frame.origin.y
}
set(value) {
frame.origin.y = value
layer.frame.origin.y = value
}
}
......@@ -130,12 +130,12 @@ public class MaterialButton : UIButton {
*/
public var width: CGFloat {
get {
return frame.size.width
return layer.frame.size.width
}
set(value) {
frame.size.width = value
layer.frame.size.width = value
if .None != shape {
frame.size.height = value
layer.frame.size.height = value
}
}
}
......@@ -145,12 +145,12 @@ public class MaterialButton : UIButton {
*/
public var height: CGFloat {
get {
return frame.size.height
return layer.frame.size.height
}
set(value) {
frame.size.height = value
layer.frame.size.height = value
if .None != shape {
frame.size.width = value
layer.frame.size.width = value
}
}
}
......
......@@ -128,10 +128,10 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/
public var x: CGFloat {
get {
return frame.origin.x
return layer.frame.origin.x
}
set(value) {
frame.origin.x = value
layer.frame.origin.x = value
}
}
......@@ -140,10 +140,10 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/
public var y: CGFloat {
get {
return frame.origin.y
return layer.frame.origin.y
}
set(value) {
frame.origin.y = value
layer.frame.origin.y = value
}
}
......@@ -152,12 +152,12 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/
public var width: CGFloat {
get {
return frame.size.width
return layer.frame.size.width
}
set(value) {
frame.size.width = value
layer.frame.size.width = value
if .None != shape {
frame.size.height = value
layer.frame.size.height = value
}
}
}
......@@ -167,12 +167,12 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/
public var height: CGFloat {
get {
return frame.size.height
return layer.frame.size.height
}
set(value) {
frame.size.height = value
layer.frame.size.height = value
if .None != shape {
frame.size.width = value
layer.frame.size.width = value
}
}
}
......
......@@ -27,7 +27,7 @@ public class MaterialTextView: UITextView {
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
/**
:name: init
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
......@@ -35,7 +35,7 @@ public class MaterialTextView: UITextView {
}
/**
:name: init
:name: init
*/
public override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
......@@ -50,7 +50,7 @@ public class MaterialTextView: UITextView {
}
/**
:name: placeholder
:name: placeholder
*/
public var placeholderLabel: UILabel? {
didSet {
......@@ -69,7 +69,7 @@ public class MaterialTextView: UITextView {
/**
:name: text
:name: text
*/
public override var text: String! {
didSet {
......@@ -78,7 +78,7 @@ public class MaterialTextView: UITextView {
}
/**
:name: attributedText
:name: attributedText
*/
public override var attributedText: NSAttributedString! {
didSet {
......@@ -87,7 +87,7 @@ public class MaterialTextView: UITextView {
}
/**
:name: textContainerInset
:name: textContainerInset
*/
public override var textContainerInset: UIEdgeInsets {
didSet {
......@@ -101,7 +101,7 @@ public class MaterialTextView: UITextView {
}
/**
:name: updateLabelConstraints
:name: updateLabelConstraints
*/
internal func updateLabelConstraints() {
if let p = placeholderLabel {
......
......@@ -113,10 +113,10 @@ public class MaterialView : UIView {
*/
public var y: CGFloat {
get {
return frame.origin.y
return layer.frame.origin.y
}
set(value) {
frame.origin.y = value
layer.frame.origin.y = value
}
}
......@@ -125,12 +125,12 @@ public class MaterialView : UIView {
*/
public var width: CGFloat {
get {
return frame.size.width
return layer.frame.size.width
}
set(value) {
frame.size.width = value
layer.frame.size.width = value
if .None != shape {
frame.size.height = value
layer.frame.size.height = value
}
}
}
......@@ -140,12 +140,12 @@ public class MaterialView : UIView {
*/
public var height: CGFloat {
get {
return frame.size.height
return layer.frame.size.height
}
set(value) {
frame.size.height = value
layer.frame.size.height = value
if .None != shape {
frame.size.width = value
layer.frame.size.width = value
}
}
}
......
......@@ -18,6 +18,13 @@
import UIKit
@objc(SearchBarViewDelegate)
public protocol SearchBarViewDelegate : MaterialDelegate {
optional func materialSearchBarDidBeginEditing(searchBarView: SearchBarView)
optional func materialSearchBarDidEndEditing(searchBarView: SearchBarView)
}
@objc(SearchBarView)
public class SearchBarView : MaterialView, UITextFieldDelegate {
/**
:name: internalBackgroundColor
......@@ -216,7 +223,7 @@ public class SearchBarView : MaterialView, UITextFieldDelegate {
views["textField"] = textField
addSubview(textField)
print(contentInsetsRef)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: textField, left: contentInsetsRef.left + textFieldInsetsRef.left, right: contentInsetsRef.right + textFieldInsetsRef.right)
// leftButtons
......@@ -300,20 +307,19 @@ public class SearchBarView : MaterialView, UITextFieldDelegate {
internal func prepareTextField() {
textField.translatesAutoresizingMaskIntoConstraints = false
textField.delegate = self
textField.placeholder = "Search"
}
public func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
public func textFieldDidBeginEditing(textField: UITextField) {
if let v: UIColor = editingBackgroundColor {
internalBackgroundColor = backgroundColor
backgroundColor = v
}
return true
(delegate as? SearchBarViewDelegate)?.materialSearchBarDidBeginEditing?(self)
}
public func textFieldShouldEndEditing(textField: UITextField) -> Bool {
public func textFieldDidEndEditing(textField: UITextField) {
backgroundColor = internalBackgroundColor
internalBackgroundColor = nil
return true
(delegate as? SearchBarViewDelegate)?.materialSearchBarDidEndEditing?(self)
}
}
......@@ -138,16 +138,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/**
:name: leftViewControllerWidth
*/
public var leftViewControllerWidth: CGFloat = 240 {
didSet {
if let v = leftView {
v.width = leftViewControllerWidth
MaterialAnimation.animationDisabled({
v.position = CGPointMake(-v.width / 2, v.height / 2)
})
}
}
}
public private(set) var leftViewControllerWidth: CGFloat = 240
/**
:name: init
......@@ -182,6 +173,33 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
super.viewDidLoad()
edgesForExtendedLayout = .None
}
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutBackdropLayer()
if let v: MaterialView = leftView {
leftViewController?.view.frame = v.bounds
}
}
/**
:name: setLeftViewControllerWidth
*/
public func setLeftViewControllerWidth(width: CGFloat, hidden: Bool, animated: Bool, duration: CFTimeInterval = 0.25) {
leftViewControllerWidth = width
MaterialAnimation.animationDisabled({
self.leftView!.width = width
})
if animated {
leftView!.animation(MaterialAnimation.position(CGPointMake((hidden ? -width : width) / 2, leftView!.position.y), duration: duration))
} else {
MaterialAnimation.animationDisabled({
self.leftView!.position.x = (hidden ? -width : width) / 2
})
}
}
/**
:name: toggleLeftViewContainer
......@@ -397,23 +415,28 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareBackdropLayer
//
private func prepareBackdropLayer() {
view.layer.addSublayer(backdropLayer)
}
//
// :name: layoutBackdropLayer
//
private func layoutBackdropLayer() {
MaterialAnimation.animationDisabled({
self.backdropLayer.frame = self.view.bounds
self.backdropLayer.zPosition = 900
self.backdropLayer.hidden = true
})
view.layer.addSublayer(backdropLayer)
}
//
// :name: prepareViewControllerWithinContainer
//
private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) {
controller.view.translatesAutoresizingMaskIntoConstraints = false
controller.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
addChildViewController(controller)
container.addSubview(controller.view)
controller.didMoveToParentViewController(self)
MaterialLayout.alignToParent(container, child: controller.view)
}
//
......
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