Commit 44b579be by Daniel Dahan

updating SideNavigationViewController API and animations

parent 654641a9
...@@ -20,14 +20,7 @@ import UIKit ...@@ -20,14 +20,7 @@ import UIKit
@objc(MaterialAnimationDelegate) @objc(MaterialAnimationDelegate)
public protocol MaterialAnimationDelegate : MaterialDelegate { public protocol MaterialAnimationDelegate : MaterialDelegate {
/**
:name: materialAnimationDidStart
*/
optional func materialAnimationDidStart(animation: CAAnimation) optional func materialAnimationDidStart(animation: CAAnimation)
/**
:name: materialAnimationDidStop
*/
optional func materialAnimationDidStop(animation: CAAnimation, finished flag: Bool) optional func materialAnimationDidStop(animation: CAAnimation, finished flag: Bool)
} }
......
...@@ -106,10 +106,10 @@ public class MaterialButton : UIButton { ...@@ -106,10 +106,10 @@ public class MaterialButton : UIButton {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return frame.origin.x return layer.frame.origin.x
} }
set(value) { set(value) {
frame.origin.x = value layer.frame.origin.x = value
} }
} }
...@@ -118,10 +118,10 @@ public class MaterialButton : UIButton { ...@@ -118,10 +118,10 @@ public class MaterialButton : UIButton {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return frame.origin.y return layer.frame.origin.y
} }
set(value) { set(value) {
frame.origin.y = value layer.frame.origin.y = value
} }
} }
...@@ -130,12 +130,12 @@ public class MaterialButton : UIButton { ...@@ -130,12 +130,12 @@ public class MaterialButton : UIButton {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return frame.size.width return layer.frame.size.width
} }
set(value) { set(value) {
frame.size.width = value layer.frame.size.width = value
if .None != shape { if .None != shape {
frame.size.height = value layer.frame.size.height = value
} }
} }
} }
...@@ -145,12 +145,12 @@ public class MaterialButton : UIButton { ...@@ -145,12 +145,12 @@ public class MaterialButton : UIButton {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return frame.size.height return layer.frame.size.height
} }
set(value) { set(value) {
frame.size.height = value layer.frame.size.height = value
if .None != shape { if .None != shape {
frame.size.width = value layer.frame.size.width = value
} }
} }
} }
......
...@@ -128,10 +128,10 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -128,10 +128,10 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/ */
public var x: CGFloat { public var x: CGFloat {
get { get {
return frame.origin.x return layer.frame.origin.x
} }
set(value) { set(value) {
frame.origin.x = value layer.frame.origin.x = value
} }
} }
...@@ -140,10 +140,10 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -140,10 +140,10 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return frame.origin.y return layer.frame.origin.y
} }
set(value) { set(value) {
frame.origin.y = value layer.frame.origin.y = value
} }
} }
...@@ -152,12 +152,12 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -152,12 +152,12 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return frame.size.width return layer.frame.size.width
} }
set(value) { set(value) {
frame.size.width = value layer.frame.size.width = value
if .None != shape { if .None != shape {
frame.size.height = value layer.frame.size.height = value
} }
} }
} }
...@@ -167,12 +167,12 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell { ...@@ -167,12 +167,12 @@ public class MaterialPulseCollectionViewCell : UICollectionViewCell {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return frame.size.height return layer.frame.size.height
} }
set(value) { set(value) {
frame.size.height = value layer.frame.size.height = value
if .None != shape { if .None != shape {
frame.size.width = value layer.frame.size.width = value
} }
} }
} }
......
...@@ -113,10 +113,10 @@ public class MaterialView : UIView { ...@@ -113,10 +113,10 @@ public class MaterialView : UIView {
*/ */
public var y: CGFloat { public var y: CGFloat {
get { get {
return frame.origin.y return layer.frame.origin.y
} }
set(value) { set(value) {
frame.origin.y = value layer.frame.origin.y = value
} }
} }
...@@ -125,12 +125,12 @@ public class MaterialView : UIView { ...@@ -125,12 +125,12 @@ public class MaterialView : UIView {
*/ */
public var width: CGFloat { public var width: CGFloat {
get { get {
return frame.size.width return layer.frame.size.width
} }
set(value) { set(value) {
frame.size.width = value layer.frame.size.width = value
if .None != shape { if .None != shape {
frame.size.height = value layer.frame.size.height = value
} }
} }
} }
...@@ -140,12 +140,12 @@ public class MaterialView : UIView { ...@@ -140,12 +140,12 @@ public class MaterialView : UIView {
*/ */
public var height: CGFloat { public var height: CGFloat {
get { get {
return frame.size.height return layer.frame.size.height
} }
set(value) { set(value) {
frame.size.height = value layer.frame.size.height = value
if .None != shape { if .None != shape {
frame.size.width = value layer.frame.size.width = value
} }
} }
} }
......
...@@ -18,6 +18,13 @@ ...@@ -18,6 +18,13 @@
import UIKit 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 { public class SearchBarView : MaterialView, UITextFieldDelegate {
/** /**
:name: internalBackgroundColor :name: internalBackgroundColor
...@@ -216,7 +223,7 @@ public class SearchBarView : MaterialView, UITextFieldDelegate { ...@@ -216,7 +223,7 @@ public class SearchBarView : MaterialView, UITextFieldDelegate {
views["textField"] = textField views["textField"] = textField
addSubview(textField) addSubview(textField)
print(contentInsetsRef)
MaterialLayout.alignToParentHorizontallyWithInsets(self, child: textField, left: contentInsetsRef.left + textFieldInsetsRef.left, right: contentInsetsRef.right + textFieldInsetsRef.right) MaterialLayout.alignToParentHorizontallyWithInsets(self, child: textField, left: contentInsetsRef.left + textFieldInsetsRef.left, right: contentInsetsRef.right + textFieldInsetsRef.right)
// leftButtons // leftButtons
...@@ -300,20 +307,19 @@ public class SearchBarView : MaterialView, UITextFieldDelegate { ...@@ -300,20 +307,19 @@ public class SearchBarView : MaterialView, UITextFieldDelegate {
internal func prepareTextField() { internal func prepareTextField() {
textField.translatesAutoresizingMaskIntoConstraints = false textField.translatesAutoresizingMaskIntoConstraints = false
textField.delegate = self textField.delegate = self
textField.placeholder = "Search"
} }
public func textFieldShouldBeginEditing(textField: UITextField) -> Bool { public func textFieldDidBeginEditing(textField: UITextField) {
if let v: UIColor = editingBackgroundColor { if let v: UIColor = editingBackgroundColor {
internalBackgroundColor = backgroundColor internalBackgroundColor = backgroundColor
backgroundColor = v backgroundColor = v
} }
return true (delegate as? SearchBarViewDelegate)?.materialSearchBarDidBeginEditing?(self)
} }
public func textFieldShouldEndEditing(textField: UITextField) -> Bool { public func textFieldDidEndEditing(textField: UITextField) {
backgroundColor = internalBackgroundColor backgroundColor = internalBackgroundColor
internalBackgroundColor = nil internalBackgroundColor = nil
return true (delegate as? SearchBarViewDelegate)?.materialSearchBarDidEndEditing?(self)
} }
} }
...@@ -138,16 +138,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -138,16 +138,7 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
/** /**
:name: leftViewControllerWidth :name: leftViewControllerWidth
*/ */
public var leftViewControllerWidth: CGFloat = 240 { public private(set) var leftViewControllerWidth: CGFloat = 240
didSet {
if let v = leftView {
v.width = leftViewControllerWidth
MaterialAnimation.animationDisabled({
v.position = CGPointMake(-v.width / 2, v.height / 2)
})
}
}
}
/** /**
:name: init :name: init
...@@ -183,6 +174,33 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -183,6 +174,33 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
edgesForExtendedLayout = .None 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 :name: toggleLeftViewContainer
*/ */
...@@ -397,23 +415,28 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer ...@@ -397,23 +415,28 @@ public class SideNavigationViewController: UIViewController, UIGestureRecognizer
// :name: prepareBackdropLayer // :name: prepareBackdropLayer
// //
private func prepareBackdropLayer() { private func prepareBackdropLayer() {
view.layer.addSublayer(backdropLayer)
}
//
// :name: layoutBackdropLayer
//
private func layoutBackdropLayer() {
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled({
self.backdropLayer.frame = self.view.bounds self.backdropLayer.frame = self.view.bounds
self.backdropLayer.zPosition = 900 self.backdropLayer.zPosition = 900
self.backdropLayer.hidden = true self.backdropLayer.hidden = true
}) })
view.layer.addSublayer(backdropLayer)
} }
// //
// :name: prepareViewControllerWithinContainer // :name: prepareViewControllerWithinContainer
// //
private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) { private func prepareViewControllerWithinContainer(controller: UIViewController, container: UIView) {
controller.view.translatesAutoresizingMaskIntoConstraints = false controller.view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
addChildViewController(controller) addChildViewController(controller)
container.addSubview(controller.view) container.addSubview(controller.view)
controller.didMoveToParentViewController(self) 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