diff --git a/.DS_Store b/.DS_Store index 8d3c9a2..34750e6 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/Example/Example/MenuController.swift b/Example/Example/MenuController.swift index f2de035..abb8dc5 100644 --- a/Example/Example/MenuController.swift +++ b/Example/Example/MenuController.swift @@ -12,17 +12,19 @@ class MenuController: UITableViewController { let segues = ["showCenterController1", "showCenterController2", "showCenterController3"] private var previousIndex: NSIndexPath? + private var searchController: UISearchController! override func viewDidLoad() { super.viewDidLoad() + configureSearchController() } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return segues.count } - override func tableView(_ tableView: UITableView, - cellForRowAt indexPath: IndexPath) -> UITableViewCell { + override func tableView(_ tableView: UITableView, + cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "menuCell")! cell.textLabel?.font = UIFont(name: "HelveticaNeue-Light", size: 15) cell.textLabel?.text = "Switch to controller \(indexPath.row + 1)" @@ -30,8 +32,8 @@ class MenuController: UITableViewController { return cell } - override func tableView(_ tableView: UITableView, - didSelectRowAt indexPath: IndexPath) { + override func tableView(_ tableView: UITableView, + didSelectRowAt indexPath: IndexPath) { if let index = previousIndex { tableView.deselectRow(at: index as IndexPath, animated: true) @@ -41,4 +43,21 @@ class MenuController: UITableViewController { previousIndex = indexPath as NSIndexPath? } + private func configureSearchController() { + searchController = UISearchController(searchResultsController: UITableViewController()) + searchController.dimsBackgroundDuringPresentation = true; + searchController.delegate = self + tableView.tableHeaderView = searchController.searchBar + } +} + +extension MenuController: UISearchControllerDelegate { + + func willPresentSearchController(_ searchController: UISearchController) { + sideMenuController?.sideMenu(toFull: true) + + } + func didDismissSearchController(_ searchController: UISearchController) { + sideMenuController?.sideMenu(toFull: false) + } } diff --git a/SideMenuController.xcodeproj/project.pbxproj b/SideMenuController.xcodeproj/project.pbxproj index b4f1c50..5b7f892 100644 --- a/SideMenuController.xcodeproj/project.pbxproj +++ b/SideMenuController.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 13F653271D3E007300700656 /* SideMenuController+CustomTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13F653241D3E007300700656 /* SideMenuController+CustomTypes.swift */; }; 13F653281D3E007300700656 /* SideMenuController+SideOver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13F653251D3E007300700656 /* SideMenuController+SideOver.swift */; }; 13F653291D3E007300700656 /* SideMenuController+SideUnder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 13F653261D3E007300700656 /* SideMenuController+SideUnder.swift */; }; + B27075BE1E2D07E100E3D41A /* SideMenuController+Animation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B27075BD1E2D07E100E3D41A /* SideMenuController+Animation.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -45,6 +46,7 @@ 13F653241D3E007300700656 /* SideMenuController+CustomTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SideMenuController+CustomTypes.swift"; path = "Source/SideMenuController+CustomTypes.swift"; sourceTree = SOURCE_ROOT; }; 13F653251D3E007300700656 /* SideMenuController+SideOver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SideMenuController+SideOver.swift"; path = "Source/SideMenuController+SideOver.swift"; sourceTree = SOURCE_ROOT; }; 13F653261D3E007300700656 /* SideMenuController+SideUnder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SideMenuController+SideUnder.swift"; path = "Source/SideMenuController+SideUnder.swift"; sourceTree = SOURCE_ROOT; }; + B27075BD1E2D07E100E3D41A /* SideMenuController+Animation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "SideMenuController+Animation.swift"; path = "Source/SideMenuController+Animation.swift"; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -126,6 +128,7 @@ 13AC23481D39187A0087E25F /* SideMenuController */ = { isa = PBXGroup; children = ( + B27075BD1E2D07E100E3D41A /* SideMenuController+Animation.swift */, 13F653241D3E007300700656 /* SideMenuController+CustomTypes.swift */, 13F653251D3E007300700656 /* SideMenuController+SideOver.swift */, 13F653261D3E007300700656 /* SideMenuController+SideUnder.swift */, @@ -248,6 +251,7 @@ 134E94E11D159C4B001C1F7D /* TransitionAnimator.swift in Sources */, 13A7586D1D12A61B004488DA /* SideContainmentSegue.swift in Sources */, 134E94E21D159C4B001C1F7D /* UIKitExtensions.swift in Sources */, + B27075BE1E2D07E100E3D41A /* SideMenuController+Animation.swift in Sources */, 13F653281D3E007300700656 /* SideMenuController+SideOver.swift in Sources */, 13F653291D3E007300700656 /* SideMenuController+SideUnder.swift in Sources */, 13F653271D3E007300700656 /* SideMenuController+CustomTypes.swift in Sources */, diff --git a/Source/SideMenuController+Animation.swift b/Source/SideMenuController+Animation.swift new file mode 100644 index 0000000..144275c --- /dev/null +++ b/Source/SideMenuController+Animation.swift @@ -0,0 +1,44 @@ +// +// SideMenuController+Animation.swift +// SideMenuController +// +// Created by Sergey Navka on 1/16/17. +// Copyright © 2017 teodorpatras. All rights reserved. +// + +extension SideMenuController { + + public func sideMenu(toFull: Bool, animation:(()->Void)? = nil, completion: ((Bool)->Void)? = nil) { + let duration = 0.25 + let valuesForChanges = valuesForSideFullScreen(toFull) + + let animationClosure: ()-> Void = { [weak self] in + self?.sidePanel.frame.size.width = valuesForChanges.sidePanelWidht + self?.sidePanel.frame.origin.x = valuesForChanges.sidePanelX + self?.centerPanel.frame.origin.x = valuesForChanges.centerPanelX + self?.sideMenuController?.view.layoutIfNeeded() + if let animation = animation { + animation() + } + } + + UIView.animate(withDuration: duration, animations: animationClosure, completion: completion) + } + + private func valuesForSideFullScreen(_ isFull: Bool) -> (sidePanelWidht: CGFloat, sidePanelX: CGFloat, centerPanelX: CGFloat) { + + var sidePanelX: CGFloat = 0.0 + var centerPanelX: CGFloat = 0.0 + let sidePanelWidht = isFull ? screenSize.width : _preferences.drawing.sidePanelWidth + + if sidePanelPosition.isPositionedLeft { + sidePanelX = 0.0 + centerPanelX = isFull ? screenSize.width : _preferences.drawing.sidePanelWidth + } else { + sidePanelX = isFull ? 0.0 : screenSize.width - _preferences.drawing.sidePanelWidth + centerPanelX = isFull ? -screenSize.width : -_preferences.drawing.sidePanelWidth + } + if !sidePanelPosition.isPositionedUnder { centerPanelX = 0.0 } + return (sidePanelWidht, sidePanelX, centerPanelX) + } +} diff --git a/Source/SideMenuController+CustomTypes.swift b/Source/SideMenuController+CustomTypes.swift index 7b20a92..0dbc061 100644 --- a/Source/SideMenuController+CustomTypes.swift +++ b/Source/SideMenuController+CustomTypes.swift @@ -28,6 +28,7 @@ public extension SideMenuController { case fadeAnimation case horizontalPan case showUnderlay + case none var statusBarAnimation: UIStatusBarAnimation { switch self {