From 1abdc72c7cd35fd6c5872a3def0fd9b1a7268328 Mon Sep 17 00:00:00 2001 From: Sergey Navka Date: Mon, 16 Jan 2017 15:57:05 +0200 Subject: [PATCH 1/2] add ability to resize menu to full scrren --- Example/Example/MenuController.swift | 27 ++++++++++-- SideMenuController.xcodeproj/project.pbxproj | 4 ++ Source/SideMenuController+Animation.swift | 44 ++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 Source/SideMenuController+Animation.swift 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) + } +} From d2c1676c45870f92f8d66dd45e7f94cca31806d8 Mon Sep 17 00:00:00 2001 From: Sergey Navka Date: Thu, 26 Jan 2017 16:45:55 +0200 Subject: [PATCH 2/2] add none action for status bar after swipe menu --- .DS_Store | Bin 6148 -> 8196 bytes Source/SideMenuController+CustomTypes.swift | 1 + 2 files changed, 1 insertion(+) diff --git a/.DS_Store b/.DS_Store index 8d3c9a26c448bbe5cfc78a1c3941b6b77529e045..34750e682ed75eefd0a71b6604e9b36361f018c1 100644 GIT binary patch literal 8196 zcmeHM-HOvd82x5{8$?_|*hNI*h2X`qbpJ0zsNMFW;ELEqFI0BZCTyc=rX;Cd?N)l@ zJE(8qV|eMk;Ctu;=$Ri&n(oTV7AZPYX3k{teP+bI}Pd!7A-D?2<)96$7;l=;)ge(3T}k+(xPmOKxfqyb;q z(f-0xx4XWzwrp>#t@W1e?)G*b_4Tb@&&n;{T)k5{Xuf*gJ?_1EFE5*zzVFZ_bv!6P zpq3HkWi<)|9v$l=9SCmU26GU z{{!9*_#%2CN9>@VlNQ_9xP!yhYMnP*&_Sec$mbeslb1?vJE;?Wx$)^(a-NgV9V=g} zk-lE}(452EaIBtaRBO3P(^?PNPTIEK+`v}OZ=QQw4_#ztQ_s>KwoyEK$7EuArlpc| zZwjNp#3?YXMzkd2|MKbI|0izTWiN5o_DX2go7`yS_r{ rf O5Uapqo8x)rFarP%jujIC 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 {