Commit ca919cfe by Daniel Dahan

development: updated MenuView and Menu to now be one object

parent 159165b9
...@@ -71,8 +71,7 @@ ...@@ -71,8 +71,7 @@
96BCB7D31CB40DC500C806FE /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78A1CB40DC500C806FE /* MaterialTextLayer.swift */; }; 96BCB7D31CB40DC500C806FE /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78A1CB40DC500C806FE /* MaterialTextLayer.swift */; };
96BCB7D41CB40DC500C806FE /* TransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78B1CB40DC500C806FE /* TransitionAnimation.swift */; }; 96BCB7D41CB40DC500C806FE /* TransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78B1CB40DC500C806FE /* TransitionAnimation.swift */; };
96BCB7D51CB40DC500C806FE /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78C1CB40DC500C806FE /* View.swift */; }; 96BCB7D51CB40DC500C806FE /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78C1CB40DC500C806FE /* View.swift */; };
96BCB7D61CB40DC500C806FE /* Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78D1CB40DC500C806FE /* Menu.swift */; }; 96BCB7D71CB40DC500C806FE /* Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* Menu.swift */; };
96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* MenuView.swift */; };
96BCB7D81CB40DC500C806FE /* MenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; }; 96BCB7D81CB40DC500C806FE /* MenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; };
96BCB7D91CB40DC500C806FE /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7901CB40DC500C806FE /* NavigationBar.swift */; }; 96BCB7D91CB40DC500C806FE /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7901CB40DC500C806FE /* NavigationBar.swift */; };
96BCB7DA1CB40DC500C806FE /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7911CB40DC500C806FE /* NavigationController.swift */; }; 96BCB7DA1CB40DC500C806FE /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7911CB40DC500C806FE /* NavigationController.swift */; };
...@@ -140,8 +139,7 @@ ...@@ -140,8 +139,7 @@
96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7971CB40DC500C806FE /* NavigationDrawerController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83C1CB4115200C806FE /* BarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* BarView.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83C1CB4115200C806FE /* BarView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7981CB40DC500C806FE /* BarView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83D1CB4115200C806FE /* RootController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7991CB40DC500C806FE /* RootController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83D1CB4115200C806FE /* RootController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7991CB40DC500C806FE /* RootController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83E1CB4115200C806FE /* Menu.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78D1CB40DC500C806FE /* Menu.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB83F1CB4115200C806FE /* Menu.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* Menu.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* MenuView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8401CB4115200C806FE /* MenuController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB8401CB4115200C806FE /* MenuController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8411CB4115200C806FE /* TabBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79A1CB40DC500C806FE /* TabBar.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB8411CB4115200C806FE /* TabBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79A1CB40DC500C806FE /* TabBar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB8421CB4115200C806FE /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 96BCB8421CB4115200C806FE /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -266,8 +264,7 @@ ...@@ -266,8 +264,7 @@
96BCB78A1CB40DC500C806FE /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; }; 96BCB78A1CB40DC500C806FE /* MaterialTextLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialTextLayer.swift; sourceTree = "<group>"; };
96BCB78B1CB40DC500C806FE /* TransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionAnimation.swift; sourceTree = "<group>"; }; 96BCB78B1CB40DC500C806FE /* TransitionAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransitionAnimation.swift; sourceTree = "<group>"; };
96BCB78C1CB40DC500C806FE /* View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; }; 96BCB78C1CB40DC500C806FE /* View.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
96BCB78D1CB40DC500C806FE /* Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Menu.swift; sourceTree = "<group>"; }; 96BCB78E1CB40DC500C806FE /* Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = Menu.swift; sourceTree = "<group>"; tabWidth = 4; };
96BCB78E1CB40DC500C806FE /* MenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = "<group>"; tabWidth = 4; };
96BCB78F1CB40DC500C806FE /* MenuController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuController.swift; sourceTree = "<group>"; }; 96BCB78F1CB40DC500C806FE /* MenuController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuController.swift; sourceTree = "<group>"; };
96BCB7901CB40DC500C806FE /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = "<group>"; }; 96BCB7901CB40DC500C806FE /* NavigationBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBar.swift; sourceTree = "<group>"; };
96BCB7911CB40DC500C806FE /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = "<group>"; }; 96BCB7911CB40DC500C806FE /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = "<group>"; };
...@@ -436,8 +433,7 @@ ...@@ -436,8 +433,7 @@
963FBF021D6696D0008F8512 /* Menu */ = { 963FBF021D6696D0008F8512 /* Menu */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB78D1CB40DC500C806FE /* Menu.swift */, 96BCB78E1CB40DC500C806FE /* Menu.swift */,
96BCB78E1CB40DC500C806FE /* MenuView.swift */,
96BCB78F1CB40DC500C806FE /* MenuController.swift */, 96BCB78F1CB40DC500C806FE /* MenuController.swift */,
); );
name = Menu; name = Menu;
...@@ -818,8 +814,7 @@ ...@@ -818,8 +814,7 @@
96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */, 96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */,
96BCB83C1CB4115200C806FE /* BarView.swift in Headers */, 96BCB83C1CB4115200C806FE /* BarView.swift in Headers */,
96BCB83D1CB4115200C806FE /* RootController.swift in Headers */, 96BCB83D1CB4115200C806FE /* RootController.swift in Headers */,
96BCB83E1CB4115200C806FE /* Menu.swift in Headers */, 96BCB83F1CB4115200C806FE /* Menu.swift in Headers */,
96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */,
96BCB8401CB4115200C806FE /* MenuController.swift in Headers */, 96BCB8401CB4115200C806FE /* MenuController.swift in Headers */,
96BCB8411CB4115200C806FE /* TabBar.swift in Headers */, 96BCB8411CB4115200C806FE /* TabBar.swift in Headers */,
96BCB8421CB4115200C806FE /* Toolbar.swift in Headers */, 96BCB8421CB4115200C806FE /* Toolbar.swift in Headers */,
...@@ -1051,7 +1046,6 @@ ...@@ -1051,7 +1046,6 @@
96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */, 96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */,
96BCB7D31CB40DC500C806FE /* MaterialTextLayer.swift in Sources */, 96BCB7D31CB40DC500C806FE /* MaterialTextLayer.swift in Sources */,
96BCB7C11CB40DC500C806FE /* Depth.swift in Sources */, 96BCB7C11CB40DC500C806FE /* Depth.swift in Sources */,
96BCB7D61CB40DC500C806FE /* Menu.swift in Sources */,
96BCB7E61CB40DC500C806FE /* TextStorage.swift in Sources */, 96BCB7E61CB40DC500C806FE /* TextStorage.swift in Sources */,
96BCB7A91CB40DC500C806FE /* FlatButton.swift in Sources */, 96BCB7A91CB40DC500C806FE /* FlatButton.swift in Sources */,
96BCB7CA1CB40DC500C806FE /* Layout.swift in Sources */, 96BCB7CA1CB40DC500C806FE /* Layout.swift in Sources */,
...@@ -1101,7 +1095,7 @@ ...@@ -1101,7 +1095,7 @@
96BCB7E21CB40DC500C806FE /* RootController.swift in Sources */, 96BCB7E21CB40DC500C806FE /* RootController.swift in Sources */,
96BCB7DC1CB40DC500C806FE /* RaisedButton.swift in Sources */, 96BCB7DC1CB40DC500C806FE /* RaisedButton.swift in Sources */,
96BCB7DD1CB40DC500C806FE /* RobotoFont.swift in Sources */, 96BCB7DD1CB40DC500C806FE /* RobotoFont.swift in Sources */,
96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */, 96BCB7D71CB40DC500C806FE /* Menu.swift in Sources */,
966ECF2A1CF4C20100BB0BDF /* CollectionReusableView.swift in Sources */, 966ECF2A1CF4C20100BB0BDF /* CollectionReusableView.swift in Sources */,
96BCB7E51CB40DC500C806FE /* TextField.swift in Sources */, 96BCB7E51CB40DC500C806FE /* TextField.swift in Sources */,
96BCB7D21CB40DC500C806FE /* TableViewCell.swift in Sources */, 96BCB7D21CB40DC500C806FE /* TableViewCell.swift in Sources */,
......
...@@ -38,508 +38,544 @@ public enum MenuDirection: Int { ...@@ -38,508 +38,544 @@ public enum MenuDirection: Int {
case right case right
} }
public class Menu { @objc(MenuDelegate)
/// A Boolean that indicates if the menu is open or not. public protocol MenuDelegate {
public private(set) var isOpened = false /// Gets called when the user taps outside menu buttons.
@objc
/// The rectangular bounds that the menu animates. optional func menu(menu: Menu, tappedAt point: CGPoint)
public var origin: CGPoint { }
didSet {
reload()
}
}
/// A preset wrapper around interimSpace. open class Menu: View {
public var interimSpacePreset = InterimSpacePreset.none { /// A Boolean that indicates if the menu is open or not.
didSet { open private(set) var isOpened = false
/// A preset wrapper around interimSpace.
open var interimSpacePreset = InterimSpacePreset.none {
didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
/// The space between views. /// The space between views.
public var interimSpace: InterimSpace { open var interimSpace: InterimSpace = 0 {
didSet { didSet {
reload() reload()
} }
} }
/// Enables the animations for the Menu. /// Enables the animations for the Menu.
public var isEnabled = true open private(set) var isEnabled = true
/// The direction in which the animation opens the menu. /// The direction in which the animation opens the menu.
public var direction: MenuDirection = .up { open var direction = MenuDirection.up {
didSet { didSet {
reload() reload()
} }
} }
/// An Array of UIViews. /// An Array of UIViews.
public var views: [UIView]? { open var views = [UIView]() {
didSet { didSet {
reload() reload()
} }
} }
/// Size of views, not including the first view. /// An Optional base view size.
public var itemSize: CGSize = CGSize(width: 48, height: 48) open var baseSize = CGSize(width: 48, height: 48)
/// An Optional base view size. /// Size of views, not including the first view.
public var baseSize: CGSize? open var itemSize = CGSize(width: 48, height: 48)
/** /**
Initializer. Initializer.
- Parameter origin: The origin position of the Menu. - Parameter coder aDecoder: An NSCoder.
- Parameter interimSpace: The interimSpace size between views. */
*/ public required init?(coder aDecoder: NSCoder) {
public init(origin: CGPoint, interimSpace: InterimSpace = 16) { super.init(coder: aDecoder)
self.origin = origin }
self.interimSpace = interimSpace
} /**
Initializer.
/// Convenience initializer. - Parameter interimSpace: The interimSpace size between views.
public convenience init() { */
self.init(origin: .zero) public convenience init(interimSpace: InterimSpace = 16) {
} self.init()
self.interimSpace = interimSpace
/// Reload the view layout. }
public func reload() {
isOpened = false /// Reload the view layout.
layoutButtons() open func reload() {
} isOpened = false
layoutButtons()
/** }
Open the Menu component with animation options.
- Parameter duration: The time for each view's animation. /**
- Parameter delay: A delay time for each view's animation. Open the Menu component with animation options.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter duration: The time for each view's animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter delay: A delay time for each view's animation.
- Parameter options: Options to pass to the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter animations: An animation block to execute on each view's animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter completion: A completion block to execute on each view's animation. - Parameter options: Options to pass to the animation.
*/ - Parameter animations: An animation block to execute on each view's animation.
public func open(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) { - Parameter completion: A completion block to execute on each view's animation.
if isEnabled { */
disable() open func open(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
switch direction { if isEnabled {
case .up: disable()
openUpAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) switch direction {
case .down: case .up:
openDownAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) openUpAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
case .left: case .down:
openLeftAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) openDownAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
case .right: case .left:
openRightAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) openLeftAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
} case .right:
} openRightAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
} }
}
/** }
Close the Menu component with animation options.
- Parameter duration: The time for each view's animation. /**
- Parameter delay: A delay time for each view's animation. Close the Menu component with animation options.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter duration: The time for each view's animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter delay: A delay time for each view's animation.
- Parameter options: Options to pass to the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter animations: An animation block to execute on each view's animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter completion: A completion block to execute on each view's animation. - Parameter options: Options to pass to the animation.
*/ - Parameter animations: An animation block to execute on each view's animation.
public func close(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) { - Parameter completion: A completion block to execute on each view's animation.
if isEnabled { */
disable() open func close(duration: TimeInterval = 0.15, delay: TimeInterval = 0, usingSpringWithDamping: CGFloat = 0.5, initialSpringVelocity: CGFloat = 0, options: UIViewAnimationOptions = [], animations: ((UIView) -> Void)? = nil, completion: ((UIView) -> Void)? = nil) {
switch direction { if isEnabled {
case .up: disable()
closeUpAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) switch direction {
case .down: case .up:
closeDownAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) closeUpAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
case .left: case .down:
closeLeftAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) closeDownAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
case .right: case .left:
closeRightAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion) closeLeftAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
} case .right:
} closeRightAnimation(duration: duration, delay: delay, usingSpringWithDamping: usingSpringWithDamping, initialSpringVelocity: initialSpringVelocity, options: options, animations: animations, completion: completion)
} }
}
/** }
Open the Menu component with animation options in the Up direction.
- Parameter duration: The time for each view's animation. /**
- Parameter delay: A delay time for each view's animation. Open the Menu component with animation options in the Up direction.
- Parameter usingSpringWithDamping: A damping ratio for the animation. - Parameter duration: The time for each view's animation.
- Parameter initialSpringVelocity: The initial velocity for the animation. - Parameter delay: A delay time for each view's animation.
- Parameter options: Options to pass to the animation. - Parameter usingSpringWithDamping: A damping ratio for the animation.
- Parameter animations: An animation block to execute on each view's animation. - Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter completion: A completion block to execute on each view's animation. - Parameter options: Options to pass to the animation.
*/ - Parameter animations: An animation block to execute on each view's animation.
private func openUpAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { - Parameter completion: A completion block to execute on each view's animation.
if let v = views { */
var base: UIView? private func openUpAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
for i in 1..<v.count { guard let base = views.first else {
if nil == base { return
base = v[0] }
}
let view: UIView = v[i] for i in 1..<views.count {
view.isHidden = false let v = views[i]
v.isHidden = false
UIView.animate(withDuration: Double(i) * duration,
delay: delay, UIView.animate(withDuration: Double(i) * duration,
usingSpringWithDamping: usingSpringWithDamping, delay: delay,
initialSpringVelocity: initialSpringVelocity, usingSpringWithDamping: usingSpringWithDamping,
options: options, initialSpringVelocity: initialSpringVelocity,
animations: { [weak self] in options: options,
if let s: Menu = self { animations: { [weak self, base = base] in
view.alpha = 1 guard let s = self else {
view.y = base!.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.interimSpace return
animations?(view) }
}
}) { [weak self] _ in v.alpha = 1
if let s: Menu = self { v.y = base.y - CGFloat(i) * s.itemSize.height - CGFloat(i) * s.interimSpace
s.enable(view: view)
if view == v.last { animations?(v)
s.isOpened = true }) { [weak self] _ in
} guard let s = self else {
completion?(view) return
} }
}
} s.enable(view: v)
}
} if v == s.views.last {
s.isOpened = true
/** }
Close the Menu component with animation options in the Up direction.
- Parameter duration: The time for each view's animation. completion?(v)
- Parameter delay: A delay time for each view's animation. }
- Parameter usingSpringWithDamping: A damping ratio for the animation. }
- Parameter initialSpringVelocity: The initial velocity for the animation. }
- Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each view's animation. /**
- Parameter completion: A completion block to execute on each view's animation. Close the Menu component with animation options in the Up direction.
*/ - Parameter duration: The time for each view's animation.
public func closeUpAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { - Parameter delay: A delay time for each view's animation.
if let v = views { - Parameter usingSpringWithDamping: A damping ratio for the animation.
for i in 1..<v.count { - Parameter initialSpringVelocity: The initial velocity for the animation.
let view: UIView = v[i] - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each view's animation.
UIView.animate(withDuration: Double(i) * duration, - Parameter completion: A completion block to execute on each view's animation.
delay: delay, */
usingSpringWithDamping: usingSpringWithDamping, private func closeUpAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
initialSpringVelocity: initialSpringVelocity,
options: options, for i in 1..<views.count {
animations: { [weak self] in let v = views[i]
if let s: Menu = self {
view.alpha = 0 UIView.animate(withDuration: Double(i) * duration,
view.y = s.origin.y delay: delay,
animations?(view) usingSpringWithDamping: usingSpringWithDamping,
} initialSpringVelocity: initialSpringVelocity,
}) { [weak self] _ in options: options,
if let s: Menu = self { animations: { [weak self] in
view.isHidden = true guard let s = self else {
s.enable(view: view) return
if view == v.last { }
s.isOpened = false
} v.alpha = 0
completion?(view) v.y = s.y
}
} animations?(v)
} }) { [weak self] _ in
} guard let s = self else {
} return
}
/**
Open the Menu component with animation options in the Down direction. v.isHidden = true
- Parameter duration: The time for each view's animation. s.enable(view: v)
- Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. if v == s.views.last {
- Parameter initialSpringVelocity: The initial velocity for the animation. s.isOpened = false
- Parameter options: Options to pass to the animation. }
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation. completion?(v)
*/ }
private func openDownAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { }
if let v = views { }
var base: UIView?
for i in 1..<v.count { /**
if nil == base { Open the Menu component with animation options in the Down direction.
base = v[0] - Parameter duration: The time for each view's animation.
} - Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation.
let view: UIView = v[i] - Parameter initialSpringVelocity: The initial velocity for the animation.
view.isHidden = false - Parameter options: Options to pass to the animation.
- Parameter animations: An animation block to execute on each view's animation.
let h: CGFloat = nil == baseSize ? itemSize.height : baseSize!.height - Parameter completion: A completion block to execute on each view's animation.
UIView.animate(withDuration: Double(i) * duration, */
delay: delay, private func openDownAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
usingSpringWithDamping: usingSpringWithDamping, guard let base = views.first else {
initialSpringVelocity: initialSpringVelocity, return
options: options, }
animations: { [weak self] in
if let s: Menu = self { for i in 1..<views.count {
view.alpha = 1 let v = views[i]
view.y = base!.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.interimSpace v.isHidden = false
animations?(view)
} let h = baseSize.height
}) { [weak self] _ in UIView.animate(withDuration: Double(i) * duration,
if let s: Menu = self { delay: delay,
s.enable(view: view) usingSpringWithDamping: usingSpringWithDamping,
if view == v.last { initialSpringVelocity: initialSpringVelocity,
s.isOpened = true options: options,
} animations: { [weak self, base = base] in
completion?(view) guard let s = self else {
} return
} }
}
} v.alpha = 1
} v.y = base.y + h + CGFloat(i - 1) * s.itemSize.height + CGFloat(i) * s.interimSpace
/** animations?(v)
Close the Menu component with animation options in the Down direction. }) { [weak self] _ in
- Parameter duration: The time for each view's animation. guard let s = self else {
- Parameter delay: A delay time for each view's animation. return
- Parameter usingSpringWithDamping: A damping ratio for the animation. }
- Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. s.enable(view: v)
- Parameter animations: An animation block to execute on each view's animation.
- Parameter completion: A completion block to execute on each view's animation. if v == s.views.last {
*/ s.isOpened = true
public func closeDownAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { }
if let v = views {
for i in 1..<v.count { completion?(v)
let view: UIView = v[i] }
}
let h: CGFloat = nil == baseSize ? itemSize.height : baseSize!.height }
UIView.animate(withDuration: Double(i) * duration,
delay: delay, /**
usingSpringWithDamping: usingSpringWithDamping, Close the Menu component with animation options in the Down direction.
initialSpringVelocity: initialSpringVelocity, - Parameter duration: The time for each view's animation.
options: options, - Parameter delay: A delay time for each view's animation.
animations: { [weak self] in - Parameter usingSpringWithDamping: A damping ratio for the animation.
if let s: Menu = self { - Parameter initialSpringVelocity: The initial velocity for the animation.
view.alpha = 0 - Parameter options: Options to pass to the animation.
view.y = s.origin.y + h - Parameter animations: An animation block to execute on each view's animation.
animations?(view) - Parameter completion: A completion block to execute on each view's animation.
} */
}) { [weak self] _ in private func closeDownAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let s: Menu = self { for i in 1..<views.count {
view.isHidden = true let v = views[i]
s.enable(view: view)
if view == v.last { let h = baseSize.height
s.isOpened = false UIView.animate(withDuration: Double(i) * duration,
} delay: delay,
completion?(view) usingSpringWithDamping: usingSpringWithDamping,
} initialSpringVelocity: initialSpringVelocity,
} options: options,
} animations: { [weak self] in
} guard let s = self else {
} return
}
/**
Open the Menu component with animation options in the Left direction. v.alpha = 0
- Parameter duration: The time for each view's animation. v.y = s.y + h
- Parameter delay: A delay time for each view's animation.
- Parameter usingSpringWithDamping: A damping ratio for the animation. animations?(v)
- Parameter initialSpringVelocity: The initial velocity for the animation. }) { [weak self] _ in
- Parameter options: Options to pass to the animation. guard let s = self else {
- Parameter animations: An animation block to execute on each view's animation. return
- Parameter completion: A completion block to execute on each view's animation. }
*/
private func openLeftAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { v.isHidden = true
if let v = views { s.enable(view: v)
var base: UIView?
for i in 1..<v.count { if v == s.views.last {
if nil == base { s.isOpened = false
base = v[0] }
}
completion?(v)
let view: UIView = v[i] }
view.isHidden = false }
}
UIView.animate(withDuration: Double(i) * duration,
delay: delay, /**
usingSpringWithDamping: usingSpringWithDamping, Open the Menu component with animation options in the Left direction.
initialSpringVelocity: initialSpringVelocity, - Parameter duration: The time for each view's animation.
options: options, - Parameter delay: A delay time for each view's animation.
animations: { [weak self] in - Parameter usingSpringWithDamping: A damping ratio for the animation.
if let s: Menu = self { - Parameter initialSpringVelocity: The initial velocity for the animation.
view.alpha = 1 - Parameter options: Options to pass to the animation.
view.x = base!.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.interimSpace - Parameter animations: An animation block to execute on each view's animation.
animations?(view) - Parameter completion: A completion block to execute on each view's animation.
} */
}) { [weak self] _ in private func openLeftAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let s: Menu = self { guard let base = views.first else {
s.enable(view: view) return
if view == v.last { }
s.isOpened = true
} for i in 1..<views.count {
completion?(view) let v = views[i]
} v.isHidden = false
}
} UIView.animate(withDuration: Double(i) * duration,
} delay: delay,
} usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity,
/** options: options,
Close the Menu component with animation options in the Left direction. animations: { [weak self, base = base] in
- Parameter duration: The time for each view's animation. guard let s = self else {
- Parameter delay: A delay time for each view's animation. return
- Parameter usingSpringWithDamping: A damping ratio for the animation. }
- Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. v.alpha = 1
- Parameter animations: An animation block to execute on each view's animation. v.x = base.x - CGFloat(i) * s.itemSize.width - CGFloat(i) * s.interimSpace
- Parameter completion: A completion block to execute on each view's animation.
*/ animations?(v)
public func closeLeftAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { }) { [weak self] _ in
if let v = views { guard let s = self else {
for i in 1..<v.count { return
let view: UIView = v[i] }
UIView.animate(withDuration: Double(i) * duration,
delay: delay, s.enable(view: v)
usingSpringWithDamping: usingSpringWithDamping,
initialSpringVelocity: initialSpringVelocity, if v == s.views.last {
options: options, s.isOpened = true
animations: { [weak self] in }
if let s: Menu = self {
view.alpha = 0 completion?(v)
view.x = s.origin.x }
animations?(view) }
} }
}) { [weak self] _ in
if let s: Menu = self { /**
view.isHidden = true Close the Menu component with animation options in the Left direction.
s.enable(view: view) - Parameter duration: The time for each view's animation.
if view == v.last { - Parameter delay: A delay time for each view's animation.
s.isOpened = false - Parameter usingSpringWithDamping: A damping ratio for the animation.
} - Parameter initialSpringVelocity: The initial velocity for the animation.
completion?(view) - Parameter options: Options to pass to the animation.
} - Parameter animations: An animation block to execute on each view's animation.
} - Parameter completion: A completion block to execute on each view's animation.
} */
} private func closeLeftAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
} for i in 1..<views.count {
let v = views[i]
/**
Open the Menu component with animation options in the Right direction. UIView.animate(withDuration: Double(i) * duration,
- Parameter duration: The time for each view's animation. delay: delay,
- Parameter delay: A delay time for each view's animation. usingSpringWithDamping: usingSpringWithDamping,
- Parameter usingSpringWithDamping: A damping ratio for the animation. initialSpringVelocity: initialSpringVelocity,
- Parameter initialSpringVelocity: The initial velocity for the animation. options: options,
- Parameter options: Options to pass to the animation. animations: { [weak self] in
- Parameter animations: An animation block to execute on each view's animation. guard let s = self else {
- Parameter completion: A completion block to execute on each view's animation. return
*/ }
private func openRightAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
if let v = views { v.alpha = 0
var base: UIView? v.x = s.x
for i in 1..<v.count {
if nil == base { animations?(v)
base = v[0] }) { [weak self] _ in
} guard let s = self else {
let view: UIView = v[i] return
view.isHidden = false }
let h: CGFloat = nil == baseSize ? itemSize.height : baseSize!.height v.isHidden = true
UIView.animate(withDuration: Double(i) * duration, s.enable(view: v)
delay: delay,
usingSpringWithDamping: usingSpringWithDamping, if v == s.views.last {
initialSpringVelocity: initialSpringVelocity, s.isOpened = false
options: options, }
animations: { [weak self] in
if let s: Menu = self { completion?(v)
view.alpha = 1 }
view.x = base!.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.interimSpace }
animations?(view) }
}
}) { [weak self] _ in /**
if let s: Menu = self { Open the Menu component with animation options in the Right direction.
s.enable(view: view) - Parameter duration: The time for each view's animation.
if view == v.last { - Parameter delay: A delay time for each view's animation.
s.isOpened = true - Parameter usingSpringWithDamping: A damping ratio for the animation.
} - Parameter initialSpringVelocity: The initial velocity for the animation.
completion?(view) - Parameter options: Options to pass to the animation.
} - Parameter animations: An animation block to execute on each view's animation.
} - Parameter completion: A completion block to execute on each view's animation.
} */
} private func openRightAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
} guard let base = views.first else {
return
/** }
Close the Menu component with animation options in the Right direction.
- Parameter duration: The time for each view's animation. for i in 1..<views.count {
- Parameter delay: A delay time for each view's animation. let v = views[i]
- Parameter usingSpringWithDamping: A damping ratio for the animation. v.isHidden = false
- Parameter initialSpringVelocity: The initial velocity for the animation.
- Parameter options: Options to pass to the animation. let h = baseSize.height
- Parameter animations: An animation block to execute on each view's animation. UIView.animate(withDuration: Double(i) * duration,
- Parameter completion: A completion block to execute on each view's animation. delay: delay,
*/ usingSpringWithDamping: usingSpringWithDamping,
public func closeRightAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) { initialSpringVelocity: initialSpringVelocity,
if let v = views { options: options,
for i in 1..<v.count { animations: { [weak self, base = base] in
let view: UIView = v[i] guard let s = self else {
return
let w: CGFloat = nil == baseSize ? itemSize.width : baseSize!.width }
UIView.animate(withDuration: Double(i) * duration,
delay: delay, v.alpha = 1
usingSpringWithDamping: usingSpringWithDamping, v.x = base.x + h + CGFloat(i - 1) * s.itemSize.width + CGFloat(i) * s.interimSpace
initialSpringVelocity: initialSpringVelocity,
options: options, animations?(v)
animations: { [weak self] in }) { [weak self] _ in
if let s: Menu = self { guard let s = self else {
view.alpha = 0 return
view.x = s.origin.x + w }
animations?(view)
} s.enable(view: v)
}) { [weak self] _ in
if let s: Menu = self { if v == s.views.last {
view.isHidden = true s.isOpened = true
s.enable(view: view) }
if view == v.last {
s.isOpened = false completion?(v)
} }
completion?(view) }
} }
}
} /**
} Close the Menu component with animation options in the Right direction.
} - Parameter duration: The time for each view's animation.
- Parameter delay: A delay time for each view's animation.
/// Layout the views. - Parameter usingSpringWithDamping: A damping ratio for the animation.
private func layoutButtons() { - Parameter initialSpringVelocity: The initial velocity for the animation.
if let v = views { - Parameter options: Options to pass to the animation.
let size: CGSize = nil == baseSize ? itemSize : baseSize! - Parameter animations: An animation block to execute on each view's animation.
for i in 0..<v.count { - Parameter completion: A completion block to execute on each view's animation.
let view: UIView = v[i] */
if 0 == i { private func closeRightAnimation(duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping: CGFloat, initialSpringVelocity: CGFloat, options: UIViewAnimationOptions, animations: ((UIView) -> Void)?, completion: ((UIView) -> Void)?) {
view.frame.size = size for i in 1..<views.count {
view.frame.origin = origin let v = views[i]
view.layer.zPosition = 10000 let w = baseSize.width
} else {
view.alpha = 0 UIView.animate(withDuration: Double(i) * duration,
view.isHidden = true delay: delay,
view.frame.size = itemSize usingSpringWithDamping: usingSpringWithDamping,
view.x = origin.x + (size.width - itemSize.width) / 2 initialSpringVelocity: initialSpringVelocity,
view.y = origin.y + (size.height - itemSize.height) / 2 options: options,
view.layer.zPosition = CGFloat(10000 - v.count - i) animations: { [weak self] in
} guard let s = self else {
} return
} }
}
v.alpha = 0
/// Disable the Menu if views exist. v.x = s.x + w
private func disable() {
if let v = views { animations?(v)
if 0 < v.count { }) { [weak self] _ in
isEnabled = false guard let s = self else {
} return
} }
}
v.isHidden = true
/** s.enable(view: v)
Enable the Menu if the last view is equal to the passed in view.
- Parameter view: UIView that is passed in to compare. if v == s.views.last {
*/ s.isOpened = false
private func enable(view: UIView) { }
if let v = views {
if view == v.last { completion?(v)
isEnabled = true }
} }
} }
}
/// Layout the views.
private func layoutButtons() {
for i in 0..<views.count {
let v = views[i]
if 0 == i {
v.frame.size = baseSize
v.layer.zPosition = 10000
} else {
v.alpha = 0
v.isHidden = true
v.frame.size = itemSize
v.x = x + (baseSize.width - itemSize.width) / 2
v.y = y + (baseSize.height - itemSize.height) / 2
v.layer.zPosition = CGFloat(10000 - views.count - i)
}
}
}
/// Disable the Menu if views exist.
private func disable() {
guard 0 < views.count else {
return
}
isEnabled = false
}
/**
Enable the Menu if the last view is equal to the passed in view.
- Parameter view: UIView that is passed in to compare.
*/
private func enable(view: UIView) {
guard view == views.last else {
return
}
isEnabled = true
}
} }
...@@ -49,63 +49,77 @@ extension UIViewController { ...@@ -49,63 +49,77 @@ extension UIViewController {
} }
@IBDesignable @IBDesignable
public class MenuController: RootController { open class MenuController: RootController {
/// Reference to the MenuView. /// Reference to the MenuView.
public private(set) lazy var menuView: MenuView = MenuView() open internal(set) lazy var menu: Menu = Menu()
/** /**
Opens the menu with a callback. Opens the menu with a callback.
- Parameter completion: An Optional callback that is executed when - Parameter completion: An Optional callback that is executed when
all menu items have been opened. all menu items have been opened.
*/ */
public func openMenu(completion: (() -> Void)? = nil) { open func open(completion: (() -> Void)? = nil) {
if true == isUserInteractionEnabled { if true == isUserInteractionEnabled {
isUserInteractionEnabled = false isUserInteractionEnabled = false
rootViewController.view.alpha = 0.5 rootViewController.view.alpha = 0.5
menuView.open(completion: completion) menu.open { [weak self] (view) in
guard let s = self else {
return
}
if view == s.menu.views.last {
completion?()
}
}
} }
} }
/** /**
Closes the menu with a callback. Opens the menu with a callback.
- Parameter completion: An Optional callback that is executed when - Parameter completion: An Optional callback that is executed when
all menu items have been closed. all menu items have been closed.
*/ */
public func closeMenu(completion: (() -> Void)? = nil) { open func close(completion: (() -> Void)? = nil) {
if false == isUserInteractionEnabled { if false == isUserInteractionEnabled {
rootViewController.view.alpha = 1 rootViewController.view.alpha = 1
menuView.close(completion: { [weak self] in menu.open { [weak self] (view) in
self?.isUserInteractionEnabled = true guard let s = self else {
completion?() return
}) }
if view == s.menu.views.last {
s.isUserInteractionEnabled = true
completion?()
}
}
} }
} }
/** /**
To execute in the order of the layout chain, override this To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you method. LayoutSubviews should be called immediately, unless you
have a certain need. have a certain need.
*/ */
public override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
rootViewController.view.frame = view.bounds rootViewController.view.frame = view.bounds
} }
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
to initialize property values and other setup operations. to initialize property values and other setup operations.
The super.prepareView method should always be called immediately The super.prepareView method should always be called immediately
when subclassing. when subclassing.
*/ */
public override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
prepareMenuView() prepareMenuView()
} }
/// Prepares the MenuView. /// Prepares the MenuView.
private func prepareMenuView() { private func prepareMenuView() {
menuView.zPosition = 1000 menu.zPosition = 1000
view.addSubview(menuView) view.addSubview(menu)
} }
} }
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@objc(MenuViewDelegate)
public protocol MenuViewDelegate {
/// Gets called when the user taps outside menu buttons.
@objc
optional func menuViewDidTapOutside(menuView: MenuView)
}
open class MenuView : PulseView {
/// References the Menu instance.
open internal(set) lazy var menu: Menu = Menu()
/// A delegation reference.
open weak var delegate: MenuViewDelegate?
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
/**
Since the subviews will be outside the bounds of this view,
we need to look at the subviews to see if we have a hit.
*/
guard !isHidden else {
return nil
}
for v in subviews {
let p = v.convert(point, from: self)
if v.bounds.contains(p) {
return v.hitTest(p, with: event)
}
}
if menu.isOpened {
delegate?.menuViewDidTapOutside?(menuView: self)
}
return super.hitTest(point, with: event)
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open override func prepareView() {
super.prepareView()
pulseAnimation = .none
clipsToBounds = false
backgroundColor = nil
}
/**
Opens the menu with a callback.
- Parameter completion: An Optional callback that is executed when
all menu items have been opened.
*/
open func open(completion: (() -> Void)? = nil) {
if true == menu.views?.first?.isUserInteractionEnabled {
menu.views?.first?.isUserInteractionEnabled = false
menu.open { [weak self] (v: UIView) in
if self?.menu.views?.last == v {
self?.menu.views?.first?.isUserInteractionEnabled = true
completion?()
}
}
}
}
/**
Closes the menu with a callback.
- Parameter completion: An Optional callback that is executed when
all menu items have been closed.
*/
open func close(completion: (() -> Void)? = nil) {
if true == menu.views?.first?.isUserInteractionEnabled {
menu.views?.first?.isUserInteractionEnabled = false
menu.close { [weak self] (v: UIView) in
if self?.menu.views?.last == v {
self?.menu.views?.first?.isUserInteractionEnabled = true
completion?()
}
}
}
}
}
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate { open class PhotoLibraryController: UIViewController {
/// A reference to a PhotoLibrary. /// A reference to a PhotoLibrary.
public private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary() public private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary()
...@@ -58,3 +58,5 @@ open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate { ...@@ -58,3 +58,5 @@ open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate {
photoLibrary.delegate = self photoLibrary.delegate = self
} }
} }
extension PhotoLibraryController: PhotoLibraryDelegate {}
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