Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

add ability to resize menu to full scrren #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
27 changes: 23 additions & 4 deletions Example/Example/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@ 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)"

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)
Expand All @@ -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)
}
}
4 changes: 4 additions & 0 deletions SideMenuController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
44 changes: 44 additions & 0 deletions Source/SideMenuController+Animation.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions Source/SideMenuController+CustomTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public extension SideMenuController {
case fadeAnimation
case horizontalPan
case showUnderlay
case none

var statusBarAnimation: UIStatusBarAnimation {
switch self {
Expand Down