diff --git a/Sample/Sample.xcodeproj/project.pbxproj b/Sample/Sample.xcodeproj/project.pbxproj index 4a5ceef..38697c1 100644 --- a/Sample/Sample.xcodeproj/project.pbxproj +++ b/Sample/Sample.xcodeproj/project.pbxproj @@ -13,10 +13,15 @@ 881EF0B21E3102E30035DEB4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 881EF0B01E3102E30035DEB4 /* LaunchScreen.storyboard */; }; 881EF0BD1E31037D0035DEB4 /* KittyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0B91E31037D0035DEB4 /* KittyViewController.swift */; }; 881EF0BE1E31037D0035DEB4 /* HostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0BA1E31037D0035DEB4 /* HostViewController.swift */; }; - 881EF0BF1E31037D0035DEB4 /* NavigationMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0BB1E31037D0035DEB4 /* NavigationMenuViewController.swift */; }; + 881EF0BF1E31037D0035DEB4 /* SampleMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 881EF0BB1E31037D0035DEB4 /* SampleMenuViewController.swift */; }; 9A15C5481EDD62BC00C4FD75 /* InteractiveSideMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 881EF0C71E31049C0035DEB4 /* InteractiveSideMenu.framework */; }; 9A15C5491EDD62BC00C4FD75 /* InteractiveSideMenu.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 881EF0C71E31049C0035DEB4 /* InteractiveSideMenu.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9A6755031EA8E30C00F0C71D /* TabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A6755021EA8E30C00F0C71D /* TabBarViewController.swift */; }; + D4028937202CEC45009F1262 /* SampleTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4028936202CEC45009F1262 /* SampleTableCell.swift */; }; + D4C58473202DD647006EF43A /* KittyViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D4C58472202DD647006EF43A /* KittyViewController.storyboard */; }; + D4C58476202DD6B0006EF43A /* Storyboardable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4C58475202DD6B0006EF43A /* Storyboardable.swift */; }; + D4C58478202DD6DF006EF43A /* TabBarViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D4C58477202DD6DF006EF43A /* TabBarViewController.storyboard */; }; + D4C5847F202DD896006EF43A /* SampleMenuViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D4C5847E202DD896006EF43A /* SampleMenuViewController.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -66,9 +71,14 @@ 881EF0B31E3102E30035DEB4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 881EF0B91E31037D0035DEB4 /* KittyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KittyViewController.swift; sourceTree = ""; }; 881EF0BA1E31037D0035DEB4 /* HostViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = HostViewController.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - 881EF0BB1E31037D0035DEB4 /* NavigationMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationMenuViewController.swift; sourceTree = ""; }; + 881EF0BB1E31037D0035DEB4 /* SampleMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleMenuViewController.swift; sourceTree = ""; }; 881EF0C21E31049C0035DEB4 /* InteractiveSideMenu.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = InteractiveSideMenu.xcodeproj; path = ../InteractiveSideMenu.xcodeproj; sourceTree = ""; }; 9A6755021EA8E30C00F0C71D /* TabBarViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TabBarViewController.swift; sourceTree = ""; }; + D4028936202CEC45009F1262 /* SampleTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleTableCell.swift; sourceTree = ""; }; + D4C58472202DD647006EF43A /* KittyViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = KittyViewController.storyboard; sourceTree = ""; }; + D4C58475202DD6B0006EF43A /* Storyboardable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storyboardable.swift; sourceTree = ""; }; + D4C58477202DD6DF006EF43A /* TabBarViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = TabBarViewController.storyboard; sourceTree = ""; }; + D4C5847E202DD896006EF43A /* SampleMenuViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SampleMenuViewController.storyboard; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -103,33 +113,70 @@ 881EF0A61E3102E30035DEB4 /* Sample */ = { isa = PBXGroup; children = ( - 881EF0C11E3103A80035DEB4 /* MenuContentScreens */, - 881EF0BA1E31037D0035DEB4 /* HostViewController.swift */, - 881EF0BB1E31037D0035DEB4 /* NavigationMenuViewController.swift */, - 881EF0A71E3102E30035DEB4 /* AppDelegate.swift */, 881EF0AB1E3102E30035DEB4 /* Main.storyboard */, - 881EF0AE1E3102E30035DEB4 /* Assets.xcassets */, - 881EF0B01E3102E30035DEB4 /* LaunchScreen.storyboard */, - 881EF0B31E3102E30035DEB4 /* Info.plist */, + 881EF0A71E3102E30035DEB4 /* AppDelegate.swift */, + D4C5847D202DD877006EF43A /* Controllers */, + D4C5847A202DD810006EF43A /* Menu Controllers */, + D4C5847C202DD859006EF43A /* Cells */, + D4C58474202DD6A2006EF43A /* Helpers */, + D4C5847B202DD828006EF43A /* Supporting Items */, ); path = Sample; sourceTree = ""; }; - 881EF0C11E3103A80035DEB4 /* MenuContentScreens */ = { + 881EF0C31E31049C0035DEB4 /* Products */ = { + isa = PBXGroup; + children = ( + 881EF0C71E31049C0035DEB4 /* InteractiveSideMenu.framework */, + ); + name = Products; + sourceTree = ""; + }; + D4C58474202DD6A2006EF43A /* Helpers */ = { + isa = PBXGroup; + children = ( + D4C58475202DD6B0006EF43A /* Storyboardable.swift */, + ); + path = Helpers; + sourceTree = ""; + }; + D4C5847A202DD810006EF43A /* Menu Controllers */ = { isa = PBXGroup; children = ( 881EF0B91E31037D0035DEB4 /* KittyViewController.swift */, + D4C58472202DD647006EF43A /* KittyViewController.storyboard */, 9A6755021EA8E30C00F0C71D /* TabBarViewController.swift */, + D4C58477202DD6DF006EF43A /* TabBarViewController.storyboard */, ); - name = MenuContentScreens; + path = "Menu Controllers"; sourceTree = ""; }; - 881EF0C31E31049C0035DEB4 /* Products */ = { + D4C5847B202DD828006EF43A /* Supporting Items */ = { isa = PBXGroup; children = ( - 881EF0C71E31049C0035DEB4 /* InteractiveSideMenu.framework */, + 881EF0AE1E3102E30035DEB4 /* Assets.xcassets */, + 881EF0B01E3102E30035DEB4 /* LaunchScreen.storyboard */, + 881EF0B31E3102E30035DEB4 /* Info.plist */, ); - name = Products; + name = "Supporting Items"; + sourceTree = ""; + }; + D4C5847C202DD859006EF43A /* Cells */ = { + isa = PBXGroup; + children = ( + D4028936202CEC45009F1262 /* SampleTableCell.swift */, + ); + path = Cells; + sourceTree = ""; + }; + D4C5847D202DD877006EF43A /* Controllers */ = { + isa = PBXGroup; + children = ( + 881EF0BA1E31037D0035DEB4 /* HostViewController.swift */, + 881EF0BB1E31037D0035DEB4 /* SampleMenuViewController.swift */, + D4C5847E202DD896006EF43A /* SampleMenuViewController.storyboard */, + ); + path = Controllers; sourceTree = ""; }; /* End PBXGroup section */ @@ -210,8 +257,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D4C5847F202DD896006EF43A /* SampleMenuViewController.storyboard in Resources */, 881EF0B21E3102E30035DEB4 /* LaunchScreen.storyboard in Resources */, + D4C58473202DD647006EF43A /* KittyViewController.storyboard in Resources */, 881EF0AF1E3102E30035DEB4 /* Assets.xcassets in Resources */, + D4C58478202DD6DF006EF43A /* TabBarViewController.storyboard in Resources */, 881EF0AD1E3102E30035DEB4 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -225,7 +275,9 @@ files = ( 881EF0BD1E31037D0035DEB4 /* KittyViewController.swift in Sources */, 881EF0BE1E31037D0035DEB4 /* HostViewController.swift in Sources */, - 881EF0BF1E31037D0035DEB4 /* NavigationMenuViewController.swift in Sources */, + D4C58476202DD6B0006EF43A /* Storyboardable.swift in Sources */, + D4028937202CEC45009F1262 /* SampleTableCell.swift in Sources */, + 881EF0BF1E31037D0035DEB4 /* SampleMenuViewController.swift in Sources */, 9A6755031EA8E30C00F0C71D /* TabBarViewController.swift in Sources */, 881EF0A81E3102E30035DEB4 /* AppDelegate.swift in Sources */, ); diff --git a/Sample/Sample/Assets.xcassets/kitten_avatar.imageset/Contents.json b/Sample/Sample/Assets.xcassets/kitten_avatar.imageset/Contents.json new file mode 100644 index 0000000..10e14b7 --- /dev/null +++ b/Sample/Sample/Assets.xcassets/kitten_avatar.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "kitten_avatar.jpeg", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Sample/Sample/Assets.xcassets/kitten_avatar.imageset/kitten_avatar.jpeg b/Sample/Sample/Assets.xcassets/kitten_avatar.imageset/kitten_avatar.jpeg new file mode 100644 index 0000000..586426c Binary files /dev/null and b/Sample/Sample/Assets.xcassets/kitten_avatar.imageset/kitten_avatar.jpeg differ diff --git a/Sample/Sample/Base.lproj/Main.storyboard b/Sample/Sample/Base.lproj/Main.storyboard index 5ad94b9..e8ee619 100644 --- a/Sample/Sample/Base.lproj/Main.storyboard +++ b/Sample/Sample/Base.lproj/Main.storyboard @@ -1,103 +1,14 @@ - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -116,139 +27,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Sample/Sample/Cells/SampleTableCell.swift b/Sample/Sample/Cells/SampleTableCell.swift new file mode 100644 index 0000000..e1ec603 --- /dev/null +++ b/Sample/Sample/Cells/SampleTableCell.swift @@ -0,0 +1,27 @@ +// +// SampleTableCell.swift +// Sample +// +// Created by Eric Miller on 2/8/18. +// Copyright © 2018 Handsome. All rights reserved. +// + +import UIKit + +class SampleTableCell: UITableViewCell { + + @IBOutlet weak var titleLabel: UILabel! + @IBOutlet private weak var selectedView: UIView! + + override func awakeFromNib() { + super.awakeFromNib() + selectionStyle = .none + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + selectedView.backgroundColor = selected ? UIColor.yellow : UIColor.clear + titleLabel.textColor = selected ? UIColor.yellow : UIColor.white + } +} diff --git a/Sample/Sample/HostViewController.swift b/Sample/Sample/Controllers/HostViewController.swift similarity index 80% rename from Sample/Sample/HostViewController.swift rename to Sample/Sample/Controllers/HostViewController.swift index 779ab81..a6578df 100644 --- a/Sample/Sample/HostViewController.swift +++ b/Sample/Sample/Controllers/HostViewController.swift @@ -42,7 +42,7 @@ class HostViewController: MenuContainerViewController { self.transitionOptions = TransitionOptions(duration: 0.4, visibleContentWidth: screenSize.width / 6) // Instantiate menu view controller by identifier - self.menuViewController = self.storyboard!.instantiateViewController(withIdentifier: "NavigationMenu") as! MenuViewController + self.menuViewController = SampleMenuViewController.storyboardViewController() // Gather content items controllers self.contentViewControllers = contentControllers() @@ -66,16 +66,9 @@ class HostViewController: MenuContainerViewController { } private func contentControllers() -> [UIViewController] { - let controllersIdentifiers = ["Kitty", "TabBar"] - var contentList = [UIViewController]() + let kittyController = KittyViewController.storyboardViewController() + let tabController = TabBarViewController.storyboardTabBarController() - // Instantiate items controllers from storyboard. - for identifier in controllersIdentifiers { - if let viewController = self.storyboard?.instantiateViewController(withIdentifier: identifier) { - contentList.append(viewController) - } - } - - return contentList + return [kittyController, tabController] } } diff --git a/Sample/Sample/Controllers/SampleMenuViewController.storyboard b/Sample/Sample/Controllers/SampleMenuViewController.storyboard new file mode 100644 index 0000000..ef8d9ab --- /dev/null +++ b/Sample/Sample/Controllers/SampleMenuViewController.storyboard @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sample/Sample/Controllers/SampleMenuViewController.swift b/Sample/Sample/Controllers/SampleMenuViewController.swift new file mode 100644 index 0000000..035562d --- /dev/null +++ b/Sample/Sample/Controllers/SampleMenuViewController.swift @@ -0,0 +1,107 @@ +// +// SampleMenuViewController.swift +// +// Copyright 2017 Handsome LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import UIKit +import InteractiveSideMenu + +/** + Menu controller is responsible for creating its content and showing/hiding menu using 'menuContainerViewController' property. + */ +class SampleMenuViewController: MenuViewController, Storyboardable { + + @IBOutlet fileprivate weak var tableView: UITableView! + @IBOutlet fileprivate weak var avatarImageView: UIImageView! + @IBOutlet fileprivate weak var avatarImageViewCenterXConstraint: NSLayoutConstraint! + + private var gradientApplied: Bool = false + + override var prefersStatusBarHidden: Bool { + return false + } + + override var preferredStatusBarStyle: UIStatusBarStyle { + return .lightContent + } + + override func viewDidLoad() { + super.viewDidLoad() + + // Select the initial row + tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: false, scrollPosition: UITableViewScrollPosition.none) + + avatarImageView.layer.cornerRadius = avatarImageView.frame.size.width/2 + } + + override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + + if !gradientApplied { + gradientApplied = true + avatarImageViewCenterXConstraint.constant = -(menuContainerViewController?.transitionOptions.visibleContentWidth ?? 0.0)/2 + + let gradient = CAGradientLayer() + let topColor = UIColor(red: 16.0/255.0, green: 12.0/255.0, blue: 54.0/255.0, alpha: 1.0) + let bottomColor = UIColor(red: 57.0/255.0, green: 33.0/255.0, blue: 61.0/255.0, alpha: 1.0) + gradient.startPoint = CGPoint(x: 0.0, y: 0.0) + gradient.endPoint = CGPoint(x: 1.0, y: 1.0) + gradient.colors = [topColor.cgColor, bottomColor.cgColor] + gradient.frame = view.bounds + view.layer.insertSublayer(gradient, at: 0) + } + } +} + +extension SampleMenuViewController: UITableViewDelegate, UITableViewDataSource { + + func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return menuContainerViewController?.contentViewControllers.count ?? 0 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SampleTableCell.self), for: indexPath) as? SampleTableCell else { + preconditionFailure("Unregistered table view cell") + } + + cell.titleLabel.text = menuContainerViewController?.contentViewControllers[indexPath.row].title ?? "A Controller" + + return cell + } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + guard let menuContainerViewController = self.menuContainerViewController else { + return + } + + menuContainerViewController.selectContentViewController(menuContainerViewController.contentViewControllers[indexPath.row]) + menuContainerViewController.hideSideMenu() + } + + func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { + let v = UIView() + v.backgroundColor = UIColor.clear + return v + } + + func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + return 0.5 + } +} diff --git a/Sample/Sample/Helpers/Storyboardable.swift b/Sample/Sample/Helpers/Storyboardable.swift new file mode 100644 index 0000000..cdef6d2 --- /dev/null +++ b/Sample/Sample/Helpers/Storyboardable.swift @@ -0,0 +1,50 @@ +// +// Storyboardable.swift +// bthere +// +// Created by Eric Miller on 11/27/17. +// Copyright © 2017 Handsome. All rights reserved. +// + +import UIKit + +protocol Storyboardable: class { + static var defaultStoryboardName: String { get } +} + +extension Storyboardable where Self: UIViewController { + static var defaultStoryboardName: String { + return String(describing: self) + } + + static func storyboardViewController() -> Self { + let storyboard = UIStoryboard(name: defaultStoryboardName, bundle: nil) + + guard let vc = storyboard.instantiateInitialViewController() as? Self else { + fatalError("Could not instantiate initial storyboard with name: \(defaultStoryboardName)") + } + + return vc + } + + static func storyboardNavigationController() -> UINavigationController { + let storyboard = UIStoryboard(name: defaultStoryboardName, bundle: nil) + + guard let nc = storyboard.instantiateInitialViewController() as? UINavigationController else { + fatalError("Could not instantiate initial storyboard with name: \(defaultStoryboardName)") + } + + return nc + } + + static func storyboardTabBarController() -> UITabBarController { + let storyboard = UIStoryboard(name: defaultStoryboardName, bundle: nil) + + guard let tc = storyboard.instantiateInitialViewController() as? UITabBarController else { + fatalError("Could not instantiate initial storyboard with name: \(defaultStoryboardName)") + } + + return tc + } +} + diff --git a/Sample/Sample/Menu Controllers/KittyViewController.storyboard b/Sample/Sample/Menu Controllers/KittyViewController.storyboard new file mode 100644 index 0000000..e5dbf17 --- /dev/null +++ b/Sample/Sample/Menu Controllers/KittyViewController.storyboard @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sample/Sample/KittyViewController.swift b/Sample/Sample/Menu Controllers/KittyViewController.swift similarity index 98% rename from Sample/Sample/KittyViewController.swift rename to Sample/Sample/Menu Controllers/KittyViewController.swift index 605fe76..64f2fa6 100644 --- a/Sample/Sample/KittyViewController.swift +++ b/Sample/Sample/Menu Controllers/KittyViewController.swift @@ -22,7 +22,7 @@ import InteractiveSideMenu /* KittyViewController is a controller relevant one of the side menu items. To indicate this it adopts `SideMenuItemContent` protocol. */ -class KittyViewController: UIViewController, SideMenuItemContent { +class KittyViewController: UIViewController, SideMenuItemContent, Storyboardable { /* Show side menu on menu button click */ diff --git a/Sample/Sample/Menu Controllers/TabBarViewController.storyboard b/Sample/Sample/Menu Controllers/TabBarViewController.storyboard new file mode 100644 index 0000000..e39a64c --- /dev/null +++ b/Sample/Sample/Menu Controllers/TabBarViewController.storyboard @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sample/Sample/TabBarViewController.swift b/Sample/Sample/Menu Controllers/TabBarViewController.swift similarity index 98% rename from Sample/Sample/TabBarViewController.swift rename to Sample/Sample/Menu Controllers/TabBarViewController.swift index 694838f..50278f0 100644 --- a/Sample/Sample/TabBarViewController.swift +++ b/Sample/Sample/Menu Controllers/TabBarViewController.swift @@ -22,7 +22,7 @@ import InteractiveSideMenu /* TabBarViewController is a controller relevant one of the side menu items. To indicate this it adopts `SideMenuItemContent` protocol. */ -class TabBarViewController: UITabBarController, SideMenuItemContent { +class TabBarViewController: UITabBarController, SideMenuItemContent, Storyboardable { } diff --git a/Sample/Sample/NavigationMenuViewController.swift b/Sample/Sample/NavigationMenuViewController.swift deleted file mode 100644 index f547bc6..0000000 --- a/Sample/Sample/NavigationMenuViewController.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// NavigationMenuViewController.swift -// -// Copyright 2017 Handsome LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import UIKit -import InteractiveSideMenu - -/** - Menu controller is responsible for creating its content and showing/hiding menu using 'menuContainerViewController' property. - */ -class NavigationMenuViewController: MenuViewController { - - let kCellReuseIdentifier = "MenuCell" - let menuItems = ["Kitty", "TabBar cats"] - - @IBOutlet weak var tableView: UITableView! - - override var prefersStatusBarHidden: Bool { - return false - } - - override func viewDidLoad() { - super.viewDidLoad() - - // Select the initial row - tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: false, scrollPosition: UITableViewScrollPosition.none) - } -} - -extension NavigationMenuViewController: UITableViewDelegate, UITableViewDataSource { - - func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return menuItems.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: kCellReuseIdentifier, for: indexPath) - cell.textLabel?.text = menuItems[indexPath.row] - - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - - guard let menuContainerViewController = self.menuContainerViewController else { - return - } - - menuContainerViewController.selectContentViewController(menuContainerViewController.contentViewControllers[indexPath.row]) - menuContainerViewController.hideSideMenu() - } -}