Commit 994edd5b by Daniel Dahan

master: merged development

parents a199e889 459aef04
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'MK' s.name = 'MK'
s.version = '1.2.0' s.version = '1.3.0'
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'
......
...@@ -19,7 +19,19 @@ ...@@ -19,7 +19,19 @@
import UIKit import UIKit
public class AddFabButton : FabButton { public class AddFabButton : FabButton {
/**
:name: lineWidth
*/
public var lineWidth: CGFloat = 2
//
// :name: verticalLine
//
private var verticalLine: UIView! private var verticalLine: UIView!
//
// :name: horizontalLine
//
private var horizontalLine: UIView! private var horizontalLine: UIView!
// //
......
...@@ -19,26 +19,22 @@ ...@@ -19,26 +19,22 @@
import UIKit import UIKit
public class FabButton : MaterialButton { public class FabButton : MaterialButton {
/**
:name: lineWidth
*/
public var lineWidth: CGFloat = 2
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
color = .redColor() prepareShadow()
backgroundColor = .redColor()
pulseColor = .whiteColor() pulseColor = .whiteColor()
backgroundColorView.layer.cornerRadius = bounds.width / 2 backgroundColorView.layer.cornerRadius = bounds.width / 2
} }
// //
// :name: pulseTouches // :name: pulseBegan
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseTouches(touches) super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3) self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1) self.transform = CGAffineTransformMakeScale(1.1, 1.1)
......
...@@ -19,30 +19,25 @@ ...@@ -19,30 +19,25 @@
import UIKit import UIKit
public class FlatButton : MaterialButton { public class FlatButton : MaterialButton {
/**
:name: textColor
*/
public var textColor: UIColor?
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
pulseColor = .whiteColor() setTitleColor(UIColor.purpleColor(), forState: .Normal)
pulseColor = .purpleColor()
backgroundColor = .clearColor()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
// //
// :name: pulseTouches // :name: pulseBegan
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseTouches(touches) super.pulseBegan(touches, withEvent: event)
textColor = titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.1)
self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
}) })
} }
} }
...@@ -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.2.0</string> <string>1.3.0</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -30,9 +30,13 @@ public class MaterialButton : UIButton { ...@@ -30,9 +30,13 @@ public class MaterialButton : UIButton {
internal var pulseView: UIView? internal var pulseView: UIView?
/** /**
:name: color :name: backgroundColor
*/ */
public var color: UIColor? public override var backgroundColor: UIColor? {
didSet {
backgroundColorView.backgroundColor = backgroundColor
}
}
/** /**
:name: pulseColor :name: pulseColor
...@@ -67,7 +71,7 @@ public class MaterialButton : UIButton { ...@@ -67,7 +71,7 @@ public class MaterialButton : UIButton {
*/ */
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event) super.touchesBegan(touches, withEvent: event)
pulseTouches(touches) pulseBegan(touches, withEvent: event)
} }
/** /**
...@@ -76,16 +80,16 @@ public class MaterialButton : UIButton { ...@@ -76,16 +80,16 @@ public class MaterialButton : UIButton {
public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) { public override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event) super.touchesEnded(touches, withEvent: event)
shrink() shrink()
removePulse() pulseEnded(touches, withEvent: event)
} }
/** /**
:name: touchesCancelled :name: touchesCancelled
*/ */
public override func touchesCancelled(touches: Set<NSObject>, withEvent event: UIEvent!) { public override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event) super.touchesCancelled(touches, withEvent: event)
shrink() shrink()
removePulse() pulseEnded(touches, withEvent: event)
} }
/** /**
...@@ -93,7 +97,6 @@ public class MaterialButton : UIButton { ...@@ -93,7 +97,6 @@ public class MaterialButton : UIButton {
*/ */
final public override func drawRect(rect: CGRect) { final public override func drawRect(rect: CGRect) {
prepareContext(rect) prepareContext(rect)
prepareShadow()
prepareButton() prepareButton()
prepareBackgroundColorView() prepareBackgroundColorView()
} }
...@@ -106,27 +109,51 @@ public class MaterialButton : UIButton { ...@@ -106,27 +109,51 @@ public class MaterialButton : UIButton {
} }
// //
// :name: pulseTouches // :name: pulseBegan
// //
internal func pulseTouches(touches: Set<NSObject>) { internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch let touch = touches.first as! UITouch
let touchLocation = touch.locationInView(self) let touchLocation = touch.locationInView(self)
pulseView = UIView() pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height) pulseView!.frame = CGRectMake(0, 0, bounds.height, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2 pulseView!.layer.cornerRadius = bounds.height / 2
pulseView!.center = touchLocation pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5) pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!) backgroundColorView.addSubview(pulseView!)
} }
// //
// :name: pulseEnded
//
internal func pulseEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
//
// :name: prepareShadow
//
internal func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
//
// :name: prepareBackgroundColorView // :name: prepareBackgroundColorView
// //
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button // so the pulse doesn't animate off the button
private func prepareBackgroundColorView() { private func prepareBackgroundColorView() {
backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true backgroundColorView.layer.masksToBounds = true
backgroundColorView.clipsToBounds = true
backgroundColorView.userInteractionEnabled = false backgroundColorView.userInteractionEnabled = false
insertSubview(backgroundColorView, atIndex: 0) insertSubview(backgroundColorView, atIndex: 0)
} }
...@@ -139,16 +166,6 @@ public class MaterialButton : UIButton { ...@@ -139,16 +166,6 @@ public class MaterialButton : UIButton {
} }
// //
// :name: prepareShadow
//
private func prepareShadow() {
layer.shadowOffset = CGSizeMake(1, 1)
layer.shadowColor = UIColor.blackColor().CGColor
layer.shadowOpacity = 0.5
layer.shadowRadius = 5
}
//
// :name: prepareContext // :name: prepareContext
// //
private func prepareContext(rect: CGRect) { private func prepareContext(rect: CGRect) {
...@@ -175,18 +192,4 @@ public class MaterialButton : UIButton { ...@@ -175,18 +192,4 @@ public class MaterialButton : UIButton {
completion: nil completion: nil
) )
} }
//
// :name: removePulse
//
private func removePulse() {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
}
) { _ in
self.pulseView?.removeFromSuperview()
self.pulseView = nil
}
}
} }
...@@ -19,31 +19,26 @@ ...@@ -19,31 +19,26 @@
import UIKit import UIKit
public class RaisedButton : MaterialButton { public class RaisedButton : MaterialButton {
/**
:name: textColor
*/
public var textColor: UIColor?
// //
// :name: prepareButton // :name: prepareButton
// //
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
color = .redColor() prepareShadow()
setTitleColor(UIColor.whiteColor(), forState: .Normal)
pulseColor = .whiteColor() pulseColor = .whiteColor()
backgroundColor = .purpleColor()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
// //
// :name: pulseTouches // :name: pulseBegan
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.pulseTouches(touches) super.pulseBegan(touches, withEvent: event)
textColor = titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.1)
self.setTitleColor(UIColor.whiteColor(), forState: .Normal)
}) })
} }
} }
......
...@@ -56,6 +56,14 @@ public protocol SideNavDelegate { ...@@ -56,6 +56,14 @@ public protocol SideNavDelegate {
optional func sideNavDidOpenRightViewContainer(nav: SideNavController, container: SideNavContainer) optional func sideNavDidOpenRightViewContainer(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidCloseRightViewContainer(nav: SideNavController, container: SideNavContainer) optional func sideNavDidCloseRightViewContainer(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidTapRight(nav: SideNavController, container: SideNavContainer) optional func sideNavDidTapRight(nav: SideNavController, container: SideNavContainer)
// bottom
optional func sideNavDidBeginBottomPan(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidChangeBottomPan(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidEndBottomPan(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidOpenBottomViewContainer(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidCloseBottomViewContainer(nav: SideNavController, container: SideNavContainer)
optional func sideNavDidTapBottom(nav: SideNavController, container: SideNavContainer)
} }
@objc(SideNavController) @objc(SideNavController)
...@@ -69,16 +77,20 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -69,16 +77,20 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
public static var shadowOffset: CGSize = CGSizeZero public static var shadowOffset: CGSize = CGSizeZero
public static var contentViewScale: CGFloat = 1 public static var contentViewScale: CGFloat = 1
public static var contentViewOpacity: CGFloat = 0.4 public static var contentViewOpacity: CGFloat = 0.4
public static var shouldHideStatusBar: Bool = true public static var hideStatusBar: Bool = true
public static var pointOfNoReturnWidth: CGFloat = 48 public static var pointOfNoReturnWidth: CGFloat = 48
public static var pointOfNoReturnheight: CGFloat = 48
public static var backdropViewContainerBackgroundColor: UIColor = .blackColor() public static var backdropViewContainerBackgroundColor: UIColor = .blackColor()
public static var animationDuration: CGFloat = 0.5 public static var animationDuration: CGFloat = 0.5
public static var leftBezelWidth: CGFloat = 16 public static var leftBezelWidth: CGFloat = 16
public static var leftViewContainerWidth: CGFloat = 270 public static var leftViewContainerWidth: CGFloat = 240
public static var leftPanFromBezel: Bool = true public static var leftPanFromBezel: Bool = true
public static var rightBezelWidth: CGFloat = 16 public static var rightBezelWidth: CGFloat = 16
public static var rightViewContainerWidth: CGFloat = 270 public static var rightViewContainerWidth: CGFloat = 240
public static var rightPanFromBezel: Bool = true public static var rightPanFromBezel: Bool = true
public static var bottomBezelHeight: CGFloat = 48
public static var bottomViewContainerHeight: CGFloat = 240
public static var bottomPanFromBezel: Bool = true
} }
/** /**
...@@ -96,8 +108,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -96,8 +108,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
/** /**
:name: isLeftContainerOpened :name: isLeftContainerOpened
*/ */
public var isLeftContainerOpened: Bool { public var isLeftContainerOpened: Bool {
return 0 == leftViewContainer?.frame.origin.x if let c = leftViewContainer {
return c.frame.origin.x != leftOriginX
}
return false
} }
/** /**
...@@ -105,15 +120,25 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -105,15 +120,25 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
*/ */
public var isRightContainerOpened: Bool { public var isRightContainerOpened: Bool {
if let c = rightViewContainer { if let c = rightViewContainer {
return c.frame.origin.x == rightOriginX - c.frame.size.width return c.frame.origin.x != rightOriginX
} }
return false return false
} }
/**
:name: isBottomContainerOpened
*/
public var isBottomContainerOpened: Bool {
if let c = bottomViewContainer {
return c.frame.origin.y != bottomOriginY
}
return false
}
/** /**
:name: isUserInteractionEnabled :name: isUserInteractionEnabled
*/ */
public private(set) var isUserInteractionEnabled: Bool { public var isUserInteractionEnabled: Bool {
get { get {
return mainViewContainer!.userInteractionEnabled return mainViewContainer!.userInteractionEnabled
} }
...@@ -141,6 +166,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -141,6 +166,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
:name: rightViewContainer :name: rightViewContainer
*/ */
public private(set) var rightViewContainer: UIView? public private(set) var rightViewContainer: UIView?
/**
:name: bottomViewContainer
*/
public private(set) var bottomViewContainer: UIView?
/** /**
:name: leftContainer :name: leftContainer
...@@ -151,6 +181,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -151,6 +181,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
:name: rightContainer :name: rightContainer
*/ */
public private(set) var rightContainer: SideNavContainer? public private(set) var rightContainer: SideNavContainer?
/**
:name: bottomContainer
*/
public private(set) var bottomContainer: SideNavContainer?
/** /**
:name: mainViewController :name: mainViewController
...@@ -166,6 +201,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -166,6 +201,11 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
:name: rightViewController :name: rightViewController
*/ */
public var rightViewController: UIViewController? public var rightViewController: UIViewController?
/**
:name: leftViewController
*/
public var bottomViewController: UIViewController?
/** /**
:name: leftPanGesture :name: leftPanGesture
...@@ -177,16 +217,25 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -177,16 +217,25 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
*/ */
public var leftTapGesture: UITapGestureRecognizer? public var leftTapGesture: UITapGestureRecognizer?
/**
:name: rightTapGesture
*/
public var rightTapGesture: UITapGestureRecognizer?
/**
:name: rightTapGesture
*/
public var bottomTapGesture: UITapGestureRecognizer?
/** /**
:name: rightPanGesture :name: rightPanGesture
*/ */
public var rightPanGesture: UIPanGestureRecognizer? public var rightPanGesture: UIPanGestureRecognizer?
/**
/** :name: rightPanGesture
:name: rightTapGesture */
*/ public var bottomPanGesture: UIPanGestureRecognizer?
public var rightTapGesture: UITapGestureRecognizer?
// //
// :name: leftOriginX // :name: leftOriginX
...@@ -201,6 +250,13 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -201,6 +250,13 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
private var rightOriginX: CGFloat { private var rightOriginX: CGFloat {
return view.bounds.width return view.bounds.width
} }
//
// :name: bottomOriginY
//
private var bottomOriginY: CGFloat {
return view.bounds.height
}
/** /**
:name: init :name: init
...@@ -223,8 +279,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -223,8 +279,8 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
self.init() self.init()
self.mainViewController = mainViewController self.mainViewController = mainViewController
self.leftViewController = leftViewController self.leftViewController = leftViewController
setupView() prepareView()
setupLeftView() prepareLeftView()
} }
/** /**
...@@ -234,8 +290,19 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -234,8 +290,19 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
self.init() self.init()
self.mainViewController = mainViewController self.mainViewController = mainViewController
self.rightViewController = rightViewController self.rightViewController = rightViewController
setupView() prepareView()
setupRightView() prepareRightView()
}
/**
:name: init
*/
public convenience init(mainViewController: UIViewController, bottomViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
self.bottomViewController = bottomViewController
prepareView()
prepareBottomView()
} }
/** /**
...@@ -246,9 +313,37 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -246,9 +313,37 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
self.mainViewController = mainViewController self.mainViewController = mainViewController
self.leftViewController = leftViewController self.leftViewController = leftViewController
self.rightViewController = rightViewController self.rightViewController = rightViewController
setupView() prepareView()
setupLeftView() prepareLeftView()
setupRightView() prepareRightView()
}
/**
:name: init
*/
public convenience init(mainViewController: UIViewController, leftViewController: UIViewController, bottomViewController: UIViewController, rightViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
self.leftViewController = leftViewController
self.bottomViewController = bottomViewController
self.rightViewController = rightViewController
prepareView()
prepareLeftView()
prepareBottomView()
prepareRightView()
}
/**
:name: init
*/
public convenience init(mainViewController: UIViewController, bottomViewController: UIViewController, rightViewController: UIViewController) {
self.init()
self.mainViewController = mainViewController
self.bottomViewController = bottomViewController
self.rightViewController = rightViewController
prepareView()
prepareBottomView()
prepareRightView()
} }
// //
...@@ -267,38 +362,9 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -267,38 +362,9 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
prepareContainedViewController(&mainViewContainer, viewController: &mainViewController) prepareContainedViewController(&mainViewContainer, viewController: &mainViewController)
prepareContainedViewController(&leftViewContainer, viewController: &leftViewController) prepareContainedViewController(&leftViewContainer, viewController: &leftViewController)
prepareContainedViewController(&rightViewContainer, viewController: &rightViewController) prepareContainedViewController(&rightViewContainer, viewController: &rightViewController)
prepareContainedViewController(&bottomViewContainer, viewController: &bottomViewController)
} }
//
// :name: viewWillTransitionToSize
//
public override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
mainViewContainer?.transform = CGAffineTransformMakeScale(1, 1)
leftViewContainer?.hidden = true
rightViewContainer?.hidden = true
coordinator.animateAlongsideTransition(nil) { _ in
self.toggleWindow()
self.backdropViewContainer?.layer.opacity = 0
self.mainViewContainer?.transform = CGAffineTransformMakeScale(1, 1)
self.isUserInteractionEnabled = true
if let vc = self.leftViewContainer {
vc.frame.origin.x = self.leftOriginX
vc.hidden = false
self.removeShadow(&self.leftViewContainer)
self.prepareLeftGestures()
}
if let vc = self.rightViewContainer {
vc.frame.origin.x = self.rightOriginX
vc.hidden = false
self.removeShadow(&self.rightViewContainer)
self.prepareRightGestures()
}
}
}
/** /**
:name: toggleLeftViewContainer :name: toggleLeftViewContainer
*/ */
...@@ -330,7 +396,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -330,7 +396,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} }
) { _ in ) { _ in
self.isUserInteractionEnabled = false self.isUserInteractionEnabled = false
self.leftViewController?.endAppearanceTransition()
} }
c.state = .Opened c.state = .Opened
delegate?.sideNavDidOpenLeftViewContainer?(self, container: c) delegate?.sideNavDidOpenLeftViewContainer?(self, container: c)
...@@ -355,13 +420,36 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -355,13 +420,36 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} }
) { _ in ) { _ in
self.isUserInteractionEnabled = false self.isUserInteractionEnabled = false
self.rightViewController?.endAppearanceTransition()
} }
c.state = .Opened c.state = .Opened
delegate?.sideNavDidOpenRightViewContainer?(self, container: c) delegate?.sideNavDidOpenRightViewContainer?(self, container: c)
} }
} }
} }
/**
:name: openRightViewContainer
*/
public func openBottomViewContainer(velocity: CGFloat = 0) {
if let vc = bottomViewContainer {
if let c = bottomContainer {
prepareContainerToOpen(&bottomViewController, viewContainer: &bottomViewContainer, state: c.state)
UIView.animateWithDuration(Double(0 == velocity ? options.animationDuration : fmax(0.1, fmin(1, Double(fabs(vc.frame.origin.y - bottomOriginY) / velocity)))),
delay: 0,
options: .CurveEaseInOut,
animations: { _ in
vc.frame.origin.y = self.bottomOriginY - vc.frame.size.height
self.backdropViewContainer?.layer.opacity = Float(options.contentViewOpacity)
self.mainViewContainer?.transform = CGAffineTransformMakeScale(options.contentViewScale, options.contentViewScale)
}
) { _ in
self.isUserInteractionEnabled = false
}
c.state = .Opened
delegate?.sideNavDidOpenRightViewContainer?(self, container: c)
}
}
}
/** /**
:name: closeLeftViewContainer :name: closeLeftViewContainer
...@@ -381,7 +469,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -381,7 +469,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
) { _ in ) { _ in
self.removeShadow(&self.leftViewContainer) self.removeShadow(&self.leftViewContainer)
self.isUserInteractionEnabled = true self.isUserInteractionEnabled = true
self.leftViewController?.endAppearanceTransition()
} }
c.state = .Closed c.state = .Closed
delegate?.sideNavDidCloseLeftViewContainer?(self, container: c) delegate?.sideNavDidCloseLeftViewContainer?(self, container: c)
...@@ -407,14 +494,39 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -407,14 +494,39 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
) { _ in ) { _ in
self.removeShadow(&self.rightViewContainer) self.removeShadow(&self.rightViewContainer)
self.isUserInteractionEnabled = true self.isUserInteractionEnabled = true
self.rightViewController?.endAppearanceTransition()
} }
c.state = .Closed c.state = .Closed
delegate?.sideNavDidCloseRightViewContainer?(self, container: c) delegate?.sideNavDidCloseRightViewContainer?(self, container: c)
} }
} }
} }
/**
:name: closeRightViewContainer
*/
public func closeBottomViewContainer(velocity: CGFloat = 0) {
if let vc = bottomViewContainer {
if let c = bottomContainer {
prepareContainerToClose(&bottomViewController, state: c.state)
UIView.animateWithDuration(Double(0 == velocity ? options.animationDuration : fmax(0.1, fmin(1, fabs(vc.frame.origin.y - bottomOriginY) / velocity))),
delay: 0,
options: .CurveEaseInOut,
animations: { _ in
vc.frame.origin.y = self.bottomOriginY
self.backdropViewContainer?.layer.opacity = 0
self.mainViewContainer?.transform = CGAffineTransformMakeScale(1, 1)
}
) { _ in
self.removeShadow(&self.bottomViewContainer)
self.isUserInteractionEnabled = true
}
c.state = .Closed
delegate?.sideNavDidCloseBottomViewContainer?(self, container: c)
}
}
}
/** /**
:name: switchMainViewController :name: switchMainViewController
*/ */
...@@ -451,6 +563,18 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -451,6 +563,18 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
closeRightViewContainer() closeRightViewContainer()
} }
} }
/**
:name: switchBottomViewController
*/
public func switchBottomViewController(viewController: UIViewController, closeBottomViewContainerViewContainer: Bool) {
removeViewController(&rightViewController)
rightViewController = viewController
prepareContainedViewController(&rightViewContainer, viewController: &rightViewController)
if closeBottomViewContainerViewContainer {
closeBottomViewContainer()
}
}
// //
// :name: gestureRecognizer // :name: gestureRecognizer
...@@ -462,38 +586,52 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -462,38 +586,52 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
if gestureRecognizer == rightPanGesture { if gestureRecognizer == rightPanGesture {
return gesturePanRightViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view)) return gesturePanRightViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view))
} }
if gestureRecognizer == bottomPanGesture {
return gesturePanBottomViewController(gestureRecognizer, withTouchPoint: touch.locationInView(view))
}
if gestureRecognizer == leftTapGesture { if gestureRecognizer == leftTapGesture {
return isLeftContainerOpened && !isPointContainedWithinViewController(&leftViewContainer, point: touch.locationInView(view)) return isLeftContainerOpened && !isPointContainedWithinViewController(&leftViewContainer, point: touch.locationInView(view))
} }
if gestureRecognizer == rightTapGesture { if gestureRecognizer == rightTapGesture {
return isRightContainerOpened && !isPointContainedWithinViewController(&rightViewContainer, point: touch.locationInView(view)) return isRightContainerOpened && !isPointContainedWithinViewController(&rightViewContainer, point: touch.locationInView(view))
} }
if gestureRecognizer == bottomTapGesture {
return isBottomContainerOpened && !isPointContainedWithinViewController(&bottomViewContainer, point: touch.locationInView(view))
}
return true return true
} }
// //
// :name: setupView // :name: prepareView
// //
internal func setupView() { internal func prepareView() {
prepareMainContainer() prepareMainContainer()
prepareBackdropContainer() prepareBackdropContainer()
} }
// //
// :name: setupLeftView // :name: prepareLeftView
// //
internal func setupLeftView() { internal func prepareLeftView() {
prepareContainer(&leftContainer, viewContainer: &leftViewContainer, originX: leftOriginX, width: options.leftViewContainerWidth) prepareContainer(&leftContainer, viewContainer: &leftViewContainer, originX: leftOriginX, originY: 0, width: options.leftViewContainerWidth, height: view.bounds.size.height)
prepareLeftGestures() prepareLeftGestures()
} }
// //
// :name: setupRightView // :name: prepareRightView
// //
internal func setupRightView() { internal func prepareRightView() {
prepareContainer(&rightContainer, viewContainer: &rightViewContainer, originX: rightOriginX, width: options.rightViewContainerWidth) prepareContainer(&rightContainer, viewContainer: &rightViewContainer, originX: rightOriginX, originY: 0, width: options.rightViewContainerWidth, height: view.bounds.size.height)
prepareRightGestures() prepareRightGestures()
} }
//
// :name: prepareBottomView
//
internal func prepareBottomView() {
prepareContainer(&bottomContainer, viewContainer: &bottomViewContainer, originX: 0, originY: bottomOriginY, width: view.bounds.size.width, height: options.bottomViewContainerHeight)
prepareBottomGestures()
}
// //
// :name: addGestures // :name: addGestures
...@@ -530,21 +668,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -530,21 +668,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
// //
internal func handleLeftPanGesture(gesture: UIPanGestureRecognizer) { internal func handleLeftPanGesture(gesture: UIPanGestureRecognizer) {
if isRightContainerOpened { return } if isRightContainerOpened { return }
if .Began == gesture.state { if let vc = leftViewContainer {
if let vc = leftViewContainer { if let c = leftContainer {
if let c = leftContainer { if .Began == gesture.state {
leftViewController?.beginAppearanceTransition(!isLeftContainerOpened, animated: true)
addShadow(&leftViewContainer) addShadow(&leftViewContainer)
toggleWindow(shouldOpen: true) toggleStatusBar(hide: true)
c.state = isLeftContainerOpened ? .Opened : .Closed c.state = isLeftContainerOpened ? .Opened : .Closed
c.point = gesture.locationInView(view) c.point = gesture.locationInView(view)
c.frame = vc.frame c.frame = vc.frame
delegate?.sideNavDidBeginLeftPan?(self, container: c) delegate?.sideNavDidBeginLeftPan?(self, container: c)
} } else if .Changed == gesture.state {
}
} else if .Changed == gesture.state {
if let vc = leftViewContainer {
if let c = leftContainer {
c.point = gesture.translationInView(gesture.view!) c.point = gesture.translationInView(gesture.view!)
let r = (vc.frame.origin.x - leftOriginX) / vc.frame.size.width let r = (vc.frame.origin.x - leftOriginX) / vc.frame.size.width
let s: CGFloat = 1 - (1 - options.contentViewScale) * r let s: CGFloat = 1 - (1 - options.contentViewScale) * r
...@@ -553,11 +686,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -553,11 +686,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
backdropViewContainer?.layer.opacity = Float(r * options.contentViewOpacity) backdropViewContainer?.layer.opacity = Float(r * options.contentViewOpacity)
mainViewContainer?.transform = CGAffineTransformMakeScale(s, s) mainViewContainer?.transform = CGAffineTransformMakeScale(s, s)
delegate?.sideNavDidChangeLeftPan?(self, container: c) delegate?.sideNavDidChangeLeftPan?(self, container: c)
} } else {
}
} else {
if let vc = leftViewContainer {
if let c = leftContainer {
c.point = gesture.velocityInView(gesture.view) c.point = gesture.velocityInView(gesture.view)
let x: CGFloat = c.point.x >= 1000 || c.point.x <= -1000 ? c.point.x : 0 let x: CGFloat = c.point.x >= 1000 || c.point.x <= -1000 ? c.point.x : 0
c.state = vc.frame.origin.x <= CGFloat(floor(leftOriginX)) + options.pointOfNoReturnWidth || c.point.x <= -1000 ? .Closed : .Opened c.state = vc.frame.origin.x <= CGFloat(floor(leftOriginX)) + options.pointOfNoReturnWidth || c.point.x <= -1000 ? .Closed : .Opened
...@@ -587,21 +716,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -587,21 +716,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
// //
internal func handleRightPanGesture(gesture: UIPanGestureRecognizer) { internal func handleRightPanGesture(gesture: UIPanGestureRecognizer) {
if isLeftContainerOpened { return } if isLeftContainerOpened { return }
if .Began == gesture.state { if let vc = rightViewContainer {
if let vc = rightViewContainer { if let c = rightContainer {
if let c = rightContainer { if .Began == gesture.state {
rightViewController?.beginAppearanceTransition(!isRightContainerOpened, animated: true)
addShadow(&rightViewContainer)
toggleWindow(shouldOpen: true)
c.state = isRightContainerOpened ? .Opened : .Closed
c.point = gesture.locationInView(view) c.point = gesture.locationInView(view)
c.state = isRightContainerOpened ? .Opened : .Closed
c.frame = vc.frame c.frame = vc.frame
addShadow(&rightViewContainer)
toggleStatusBar(hide: true)
delegate?.sideNavDidBeginRightPan?(self, container: c) delegate?.sideNavDidBeginRightPan?(self, container: c)
} } else if .Changed == gesture.state {
}
} else if .Changed == gesture.state {
if let vc = rightViewContainer {
if let c = rightContainer {
c.point = gesture.translationInView(gesture.view!) c.point = gesture.translationInView(gesture.view!)
let r = (rightOriginX - vc.frame.origin.x) / vc.frame.size.width let r = (rightOriginX - vc.frame.origin.x) / vc.frame.size.width
let s: CGFloat = 1 - (1 - options.contentViewScale) * r let s: CGFloat = 1 - (1 - options.contentViewScale) * r
...@@ -611,11 +735,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -611,11 +735,7 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
backdropViewContainer?.layer.opacity = Float(r * options.contentViewOpacity) backdropViewContainer?.layer.opacity = Float(r * options.contentViewOpacity)
mainViewContainer?.transform = CGAffineTransformMakeScale(s, s) mainViewContainer?.transform = CGAffineTransformMakeScale(s, s)
delegate?.sideNavDidChangeRightPan?(self, container: c) delegate?.sideNavDidChangeRightPan?(self, container: c)
} } else {
}
} else {
if let vc = rightViewContainer {
if let c = rightContainer {
c.point = gesture.velocityInView(gesture.view) c.point = gesture.velocityInView(gesture.view)
let x: CGFloat = c.point.x <= -1000 || c.point.x >= 1000 ? c.point.x : 0 let x: CGFloat = c.point.x <= -1000 || c.point.x >= 1000 ? c.point.x : 0
c.state = vc.frame.origin.x >= CGFloat(floor(rightOriginX) - options.pointOfNoReturnWidth) || c.point.x >= 1000 ? .Closed : .Opened c.state = vc.frame.origin.x >= CGFloat(floor(rightOriginX) - options.pointOfNoReturnWidth) || c.point.x >= 1000 ? .Closed : .Opened
...@@ -639,6 +759,63 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -639,6 +759,63 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
closeRightViewContainer() closeRightViewContainer()
} }
} }
//
// :name: handleRightPanGesture
//
internal func handleBottomPanGesture(gesture: UIPanGestureRecognizer) {
if isLeftContainerOpened || isRightContainerOpened { return }
if .Began == gesture.state {
if let vc = bottomViewContainer {
if let c = bottomContainer {
addShadow(&bottomViewContainer)
toggleStatusBar(hide: true)
c.state = isBottomContainerOpened ? .Opened : .Closed
c.point = gesture.locationInView(view)
c.frame = vc.frame
delegate?.sideNavDidBeginBottomPan?(self, container: c)
}
}
} else if .Changed == gesture.state {
if let vc = bottomViewContainer {
if let c = bottomContainer {
c.point = gesture.translationInView(gesture.view!)
let r = (bottomOriginY - vc.frame.origin.y) / vc.frame.size.height
let s: CGFloat = 1 - (1 - options.contentViewScale) * r
let m: CGFloat = bottomOriginY - vc.frame.size.height
let y: CGFloat = c.frame.origin.y + c.point.y
vc.frame.origin.y = y > bottomOriginY ? bottomOriginY : y < m ? m : y
backdropViewContainer?.layer.opacity = Float(r * options.contentViewOpacity)
mainViewContainer?.transform = CGAffineTransformMakeScale(s, s)
delegate?.sideNavDidChangeBottomPan?(self, container: c)
}
}
} else {
if let vc = bottomViewContainer {
if let c = bottomContainer {
c.point = gesture.velocityInView(gesture.view)
let y: CGFloat = c.point.y <= -1000 || c.point.y >= 1000 ? c.point.y : 0
c.state = vc.frame.origin.y >= CGFloat(floor(bottomOriginY) - options.pointOfNoReturnheight) || c.point.y >= 1000 ? .Closed : .Opened
if .Closed == c.state {
closeBottomViewContainer(velocity: y)
} else {
openBottomViewContainer(velocity: y)
}
delegate?.sideNavDidEndBottomPan?(self, container: c)
}
}
}
}
//
// :name: handleRightTapGesture
//
internal func handleBottomTapGesture(gesture: UIPanGestureRecognizer) {
if let c = bottomContainer {
delegate?.sideNavDidTapBottom?(self, container: c)
closeBottomViewContainer()
}
}
// //
// :name: addShadow // :name: addShadow
...@@ -664,16 +841,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -664,16 +841,16 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} }
// //
// :name: toggleWindow // :name: toggleStatusBar
// //
private func toggleWindow(shouldOpen: Bool = false) { private func toggleStatusBar(hide: Bool = false) {
if options.shouldHideStatusBar { if options.hideStatusBar {
if isViewBasedAppearance { if isViewBasedAppearance {
UIApplication.sharedApplication().setStatusBarHidden(shouldOpen, withAnimation: .Slide) UIApplication.sharedApplication().setStatusBarHidden(hide, withAnimation: .Slide)
} else { } else {
dispatch_async(dispatch_get_main_queue(), { dispatch_async(dispatch_get_main_queue(), {
if let w = UIApplication.sharedApplication().keyWindow { if let w = UIApplication.sharedApplication().keyWindow {
w.windowLevel = UIWindowLevelStatusBar + (shouldOpen ? 1 : 0) w.windowLevel = hide ? UIWindowLevelStatusBar + 1 : 0
} }
}) })
} }
...@@ -697,6 +874,20 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -697,6 +874,20 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
private func gesturePanLeftViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool { private func gesturePanLeftViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool {
return isLeftContainerOpened || options.leftPanFromBezel && isLeftPointContainedWithinRect(point) return isLeftContainerOpened || options.leftPanFromBezel && isLeftPointContainedWithinRect(point)
} }
//
// :name: gesturePanRightViewController
//
private func gesturePanRightViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool {
return isRightContainerOpened || options.rightPanFromBezel && isRightPointContainedWithinRect(point)
}
//
// :name: gesturePanRightViewController
//
private func gesturePanBottomViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool {
return isBottomContainerOpened || options.bottomPanFromBezel && isBottomPointContainedWithinRect(point)
}
// //
// :name: isLeftPointContainedWithinRect // :name: isLeftPointContainedWithinRect
...@@ -710,13 +901,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -710,13 +901,6 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} }
// //
// :name: gesturePanRightViewController
//
private func gesturePanRightViewController(gesture: UIGestureRecognizer, withTouchPoint point: CGPoint) -> Bool {
return isRightContainerOpened || options.rightPanFromBezel && isRightPointContainedWithinRect(point)
}
//
// :name: isRightPointContainedWithinRect // :name: isRightPointContainedWithinRect
// //
private func isRightPointContainedWithinRect(point: CGPoint) -> Bool { private func isRightPointContainedWithinRect(point: CGPoint) -> Bool {
...@@ -726,6 +910,17 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -726,6 +910,17 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
CGRectDivide(view.bounds, &t, &r, w, .MinXEdge) CGRectDivide(view.bounds, &t, &r, w, .MinXEdge)
return CGRectContainsPoint(r, point) return CGRectContainsPoint(r, point)
} }
//
// :name: isBottomPointContainedWithinRect
//
private func isBottomPointContainedWithinRect(point: CGPoint) -> Bool {
var r: CGRect = CGRectZero
var t: CGRect = CGRectZero
let h: CGFloat = bottomOriginY - options.bottomBezelHeight
CGRectDivide(view.bounds, &t, &r, h, .MinYEdge)
return CGRectContainsPoint(r, point)
}
// //
// :name: isPointContainedWithinViewController // :name: isPointContainedWithinViewController
...@@ -765,15 +960,33 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -765,15 +960,33 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
removeGestures(&leftPanGesture, tap: &leftTapGesture) removeGestures(&leftPanGesture, tap: &leftTapGesture)
addGestures(&leftPanGesture, panSelector: "handleLeftPanGesture:", tap: &leftTapGesture, tapSelector: "handleLeftTapGesture:") addGestures(&leftPanGesture, panSelector: "handleLeftPanGesture:", tap: &leftTapGesture, tapSelector: "handleLeftTapGesture:")
} }
//
// :name: prepareRightGestures
//
private func prepareRightGestures() {
removeGestures(&rightPanGesture, tap: &rightTapGesture)
addGestures(&rightPanGesture, panSelector: "handleRightPanGesture:", tap: &rightTapGesture, tapSelector: "handleRightTapGesture:")
}
//
// :name: prepareBottomGestures
//
private func prepareBottomGestures() {
removeGestures(&bottomPanGesture, tap: &bottomTapGesture)
addGestures(&bottomPanGesture, panSelector: "handleBottomPanGesture:", tap: &bottomTapGesture, tapSelector: "handleBottomTapGesture:")
}
// //
// :name: prepareContainer // :name: prepareContainer
// //
private func prepareContainer(inout container: SideNavContainer?, inout viewContainer: UIView?, originX: CGFloat, width: CGFloat) { private func prepareContainer(inout container: SideNavContainer?, inout viewContainer: UIView?, originX: CGFloat, originY: CGFloat, width: CGFloat, height: CGFloat) {
container = SideNavContainer(state: .Closed, point: CGPointZero, frame: CGRectZero) container = SideNavContainer(state: .Closed, point: CGPointZero, frame: CGRectZero)
var b: CGRect = view.bounds var b: CGRect = view.bounds
b.size.width = width b.size.width = width
b.size.height = height
b.origin.x = originX b.origin.x = originX
b.origin.y = originY
viewContainer = UIView(frame: b) viewContainer = UIView(frame: b)
viewContainer!.backgroundColor = .clearColor() viewContainer!.backgroundColor = .clearColor()
viewContainer!.autoresizingMask = .FlexibleHeight viewContainer!.autoresizingMask = .FlexibleHeight
...@@ -781,28 +994,18 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg ...@@ -781,28 +994,18 @@ public class SideNavController: MaterialViewController, UIGestureRecognizerDeleg
} }
// //
// :name: prepareRightGestures
//
private func prepareRightGestures() {
removeGestures(&rightPanGesture, tap: &rightTapGesture)
addGestures(&rightPanGesture, panSelector: "handleRightPanGesture:", tap: &rightTapGesture, tapSelector: "handleRightTapGesture:")
}
//
// :name: prepareContainerToOpen // :name: prepareContainerToOpen
// //
private func prepareContainerToOpen(inout viewController: UIViewController?, inout viewContainer: UIView?, state: SideNavState) { private func prepareContainerToOpen(inout viewController: UIViewController?, inout viewContainer: UIView?, state: SideNavState) {
viewController?.beginAppearanceTransition(.Opened == state, animated: true)
addShadow(&viewContainer) addShadow(&viewContainer)
toggleWindow(shouldOpen: true) toggleStatusBar(hide: true)
} }
// //
// :name: prepareContainerToClose // :name: prepareContainerToClose
// //
private func prepareContainerToClose(inout viewController: UIViewController?, state: SideNavState) { private func prepareContainerToClose(inout viewController: UIViewController?, state: SideNavState) {
viewController?.beginAppearanceTransition(.Opened == state, animated: true) toggleStatusBar()
toggleWindow()
} }
// //
......
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