Commit ca919cfe by Daniel Dahan

development: updated MenuView and Menu to now be one object

parent 159165b9
......@@ -71,8 +71,7 @@
96BCB7D31CB40DC500C806FE /* MaterialTextLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78A1CB40DC500C806FE /* MaterialTextLayer.swift */; };
96BCB7D41CB40DC500C806FE /* TransitionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78B1CB40DC500C806FE /* TransitionAnimation.swift */; };
96BCB7D51CB40DC500C806FE /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78C1CB40DC500C806FE /* View.swift */; };
96BCB7D61CB40DC500C806FE /* Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78D1CB40DC500C806FE /* Menu.swift */; };
96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* MenuView.swift */; };
96BCB7D71CB40DC500C806FE /* Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* Menu.swift */; };
96BCB7D81CB40DC500C806FE /* MenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB78F1CB40DC500C806FE /* MenuController.swift */; };
96BCB7D91CB40DC500C806FE /* NavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7901CB40DC500C806FE /* NavigationBar.swift */; };
96BCB7DA1CB40DC500C806FE /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB7911CB40DC500C806FE /* NavigationController.swift */; };
......@@ -140,8 +139,7 @@
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, ); }; };
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 /* MenuView.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* MenuView.swift */; settings = {ATTRIBUTES = (Public, ); }; };
96BCB83F1CB4115200C806FE /* Menu.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB78E1CB40DC500C806FE /* Menu.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, ); }; };
96BCB8421CB4115200C806FE /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
......@@ -266,8 +264,7 @@
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>"; };
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 /* MenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = "<group>"; tabWidth = 4; };
96BCB78E1CB40DC500C806FE /* Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = Menu.swift; sourceTree = "<group>"; tabWidth = 4; };
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>"; };
96BCB7911CB40DC500C806FE /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = "<group>"; };
......@@ -436,8 +433,7 @@
963FBF021D6696D0008F8512 /* Menu */ = {
isa = PBXGroup;
children = (
96BCB78D1CB40DC500C806FE /* Menu.swift */,
96BCB78E1CB40DC500C806FE /* MenuView.swift */,
96BCB78E1CB40DC500C806FE /* Menu.swift */,
96BCB78F1CB40DC500C806FE /* MenuController.swift */,
);
name = Menu;
......@@ -818,8 +814,7 @@
96BCB83B1CB4115200C806FE /* NavigationDrawerController.swift in Headers */,
96BCB83C1CB4115200C806FE /* BarView.swift in Headers */,
96BCB83D1CB4115200C806FE /* RootController.swift in Headers */,
96BCB83E1CB4115200C806FE /* Menu.swift in Headers */,
96BCB83F1CB4115200C806FE /* MenuView.swift in Headers */,
96BCB83F1CB4115200C806FE /* Menu.swift in Headers */,
96BCB8401CB4115200C806FE /* MenuController.swift in Headers */,
96BCB8411CB4115200C806FE /* TabBar.swift in Headers */,
96BCB8421CB4115200C806FE /* Toolbar.swift in Headers */,
......@@ -1051,7 +1046,6 @@
96BCB7DF1CB40DC500C806FE /* SearchBarController.swift in Sources */,
96BCB7D31CB40DC500C806FE /* MaterialTextLayer.swift in Sources */,
96BCB7C11CB40DC500C806FE /* Depth.swift in Sources */,
96BCB7D61CB40DC500C806FE /* Menu.swift in Sources */,
96BCB7E61CB40DC500C806FE /* TextStorage.swift in Sources */,
96BCB7A91CB40DC500C806FE /* FlatButton.swift in Sources */,
96BCB7CA1CB40DC500C806FE /* Layout.swift in Sources */,
......@@ -1101,7 +1095,7 @@
96BCB7E21CB40DC500C806FE /* RootController.swift in Sources */,
96BCB7DC1CB40DC500C806FE /* RaisedButton.swift in Sources */,
96BCB7DD1CB40DC500C806FE /* RobotoFont.swift in Sources */,
96BCB7D71CB40DC500C806FE /* MenuView.swift in Sources */,
96BCB7D71CB40DC500C806FE /* Menu.swift in Sources */,
966ECF2A1CF4C20100BB0BDF /* CollectionReusableView.swift in Sources */,
96BCB7E51CB40DC500C806FE /* TextField.swift in Sources */,
96BCB7D21CB40DC500C806FE /* TableViewCell.swift in Sources */,
......
......@@ -49,63 +49,77 @@ extension UIViewController {
}
@IBDesignable
public class MenuController: RootController {
open class MenuController: RootController {
/// 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.
- Parameter completion: An Optional callback that is executed when
all menu items have been opened.
*/
public func openMenu(completion: (() -> Void)? = 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 == isUserInteractionEnabled {
isUserInteractionEnabled = false
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.
- Parameter completion: An Optional callback that is executed when
all menu items have been closed.
*/
public func closeMenu(completion: (() -> Void)? = nil) {
/**
Opens 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 false == isUserInteractionEnabled {
rootViewController.view.alpha = 1
menuView.close(completion: { [weak self] in
self?.isUserInteractionEnabled = true
completion?()
})
menu.open { [weak self] (view) in
guard let s = self else {
return
}
if view == s.menu.views.last {
s.isUserInteractionEnabled = true
completion?()
}
}
}
}
/**
To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you
have a certain need.
*/
public override func layoutSubviews() {
To execute in the order of the layout chain, override this
method. LayoutSubviews should be called immediately, unless you
have a certain need.
*/
open override func layoutSubviews() {
super.layoutSubviews()
rootViewController.view.frame = view.bounds
}
/**
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.
*/
public override func prepareView() {
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()
prepareMenuView()
}
/// Prepares the MenuView.
private func prepareMenuView() {
menuView.zPosition = 1000
view.addSubview(menuView)
menu.zPosition = 1000
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 @@
import UIKit
open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate {
open class PhotoLibraryController: UIViewController {
/// A reference to a PhotoLibrary.
public private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary()
......@@ -58,3 +58,5 @@ open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate {
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