Skip to content

Commit

Permalink
Added option to disable sideMenu on specific view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
evnaz committed Feb 1, 2015
1 parent 974f500 commit 5b2c534
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 19 deletions.
4 changes: 4 additions & 0 deletions Example/SwiftSideMenu.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
5C132590198E2A9A00CA49BE /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5C13258F198E2A9A00CA49BE /* Images.xcassets */; };
5C13259C198E2A9A00CA49BE /* SwiftSideMenuTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C13259B198E2A9A00CA49BE /* SwiftSideMenuTests.swift */; };
5C1325AA198E2AB300CA49BE /* image.png in Resources */ = {isa = PBXBuildFile; fileRef = 5C1325A7198E2AB300CA49BE /* image.png */; };
5C6D6A271A7E26380047FE0D /* ViewController2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6D6A261A7E26380047FE0D /* ViewController2.swift */; };
9E4766FC19DDBCE900FCEACC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5C13258C198E2A9A00CA49BE /* Main.storyboard */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -44,6 +45,7 @@
5C13259A198E2A9A00CA49BE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5C13259B198E2A9A00CA49BE /* SwiftSideMenuTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftSideMenuTests.swift; sourceTree = "<group>"; };
5C1325A7198E2AB300CA49BE /* image.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = image.png; sourceTree = "<group>"; };
5C6D6A261A7E26380047FE0D /* ViewController2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController2.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -79,6 +81,7 @@
1429139219DA9F4D0025188A /* MyNavigationController.swift */,
1429137C19D97A4F0025188A /* MyMenuTableViewController.swift */,
5C13258A198E2A9A00CA49BE /* ViewController.swift */,
5C6D6A261A7E26380047FE0D /* ViewController2.swift */,
);
name = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -253,6 +256,7 @@
5C13258B198E2A9A00CA49BE /* ViewController.swift in Sources */,
1429137D19D97A4F0025188A /* MyMenuTableViewController.swift in Sources */,
14EAB63D19DD4E95006A90FC /* ENSideMenu.swift in Sources */,
5C6D6A271A7E26380047FE0D /* ViewController2.swift in Sources */,
1429139319DA9F4D0025188A /* MyNavigationController.swift in Sources */,
5C132589198E2A9A00CA49BE /* AppDelegate.swift in Sources */,
);
Expand Down
20 changes: 7 additions & 13 deletions Example/SwiftSideMenu/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6249" systemVersion="14A379a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="xKr-44-F3h">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14C106a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="xKr-44-F3h">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6243"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<scenes>
<!--SwiftSideMenu-->
Expand Down Expand Up @@ -44,7 +44,7 @@
<!--ViewController 2-->
<scene sceneID="ZaE-bk-iww">
<objects>
<viewController storyboardIdentifier="ViewController2" title="ViewController 2" id="gMT-kX-3ov" sceneMemberID="viewController">
<viewController storyboardIdentifier="ViewController2" title="ViewController 2" id="gMT-kX-3ov" customClass="ViewController2" customModule="SwiftSideMenu" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="pS4-Ko-kwh"/>
<viewControllerLayoutGuide type="bottom" id="hT2-oc-fas"/>
Expand All @@ -53,24 +53,18 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ViewController 2" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c9j-pg-AvJ">
<rect key="frame" x="237" y="290" width="126" height="21"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="c9j-pg-AvJ">
<rect key="frame" x="237.5" y="280" width="125.5" height="41"/>
<string key="text">ViewController 2
Menu disabled</string>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="0re-oY-tCL">
<rect key="frame" x="0.0" y="331" width="600" height="269"/>
<color key="backgroundColor" red="0.95239502333016968" green="1" blue="0.22673820174917236" alpha="1" colorSpace="calibratedRGB"/>
</view>
</subviews>
<color key="backgroundColor" red="0.1447979539" green="1" blue="0.66376489859999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="0re-oY-tCL" firstAttribute="top" secondItem="c9j-pg-AvJ" secondAttribute="bottom" constant="20" id="DFk-ij-CZi"/>
<constraint firstItem="0re-oY-tCL" firstAttribute="leading" secondItem="58r-My-kH9" secondAttribute="leading" id="E7b-xC-Cr3"/>
<constraint firstAttribute="centerX" secondItem="c9j-pg-AvJ" secondAttribute="centerX" id="Ghg-G2-qvS"/>
<constraint firstAttribute="trailing" secondItem="0re-oY-tCL" secondAttribute="trailing" id="Uf8-sD-PCq"/>
<constraint firstItem="hT2-oc-fas" firstAttribute="top" secondItem="0re-oY-tCL" secondAttribute="bottom" id="Zym-BY-4pm"/>
<constraint firstAttribute="centerY" secondItem="c9j-pg-AvJ" secondAttribute="centerY" id="sEd-le-mVy"/>
</constraints>
</view>
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftSideMenu/MyNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyNavigationController: ENSideMenuNavigationController, ENSideMenuDelegate
super.viewDidLoad()

sideMenu = ENSideMenu(sourceView: self.view, menuTableViewController: MyMenuTableViewController(), menuPosition:.Left)
sideMenu?.delegate = self //optional
//sideMenu?.delegate = self //optional
sideMenu?.menuWidth = 180.0 // optional, default is 160
//sideMenu?.bouncingEnabled = false

Expand Down
17 changes: 15 additions & 2 deletions Example/SwiftSideMenu/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import UIKit

class ViewController: UIViewController {
class ViewController: UIViewController, ENSideMenuDelegate {


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.sideMenuController()?.sideMenu?.delegate = self;
}

override func didReceiveMemoryWarning() {
Expand All @@ -26,5 +26,18 @@ class ViewController: UIViewController {
toggleSideMenuView()
}

// MARK: - ENSideMenu Delegate
func sideMenuWillOpen() {
println("sideMenuWillOpen")
}

func sideMenuWillClose() {
println("sideMenuWillClose")
}

func sideMenuShouldOpenSideMenu() -> Bool {
println("sideMenuShouldOpenSideMenu")
return true;
}
}

49 changes: 49 additions & 0 deletions Example/SwiftSideMenu/ViewController2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// ViewController2.swift
// SwiftSideMenu
//
// Created by Evgeny on 01.02.15.
// Copyright (c) 2015 Evgeny Nazarov. All rights reserved.
//

import UIKit

class ViewController2: UIViewController, ENSideMenuDelegate {

override func viewDidLoad() {
super.viewDidLoad()
//Move next line to viewWillAppear functon if you store your view controllers
self.sideMenuController()?.sideMenu?.delegate = self;
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - ENSideMenu Delegate
func sideMenuWillOpen() {
println("sideMenuWillOpen")
}

func sideMenuWillClose() {
println("sideMenuWillClose")
}

func sideMenuShouldOpenSideMenu() -> Bool {
println("sideMenuShouldOpenSideMenu")
return false;
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/

}
4 changes: 4 additions & 0 deletions Library/ENSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
@objc public protocol ENSideMenuDelegate {
optional func sideMenuWillOpen()
optional func sideMenuWillClose()
optional func sideMenuShouldOpenSideMenu () -> Bool
}

@objc public protocol ENSideMenuProtocol {
Expand Down Expand Up @@ -166,6 +167,9 @@ public class ENSideMenu : NSObject {
}

private func toggleMenu (shouldOpen: Bool) {
if (shouldOpen && delegate?.sideMenuShouldOpenSideMenu?() == false) {
return;
}
updateSideMenuApperanceIfNeeded()
isMenuOpen = shouldOpen
if (bouncingEnabled) {
Expand Down
Binary file not shown.
10 changes: 8 additions & 2 deletions ObjCExample/ObjCExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KTz-rF-h3y">
<rect key="frame" x="95" y="144" width="600" height="600"/>
<color key="backgroundColor" red="0.28957670070000002" green="0.48937046750000002" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</view>
</subviews>
<color key="backgroundColor" red="1" green="0.48002197327328211" blue="0.37288562610665177" alpha="1" colorSpace="calibratedRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
Expand All @@ -32,7 +38,7 @@
<view key="view" contentMode="scaleToFill" id="Yt1-PX-tEI">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.289576700699815" green="0.48937046753899072" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="d3y-xX-xkf" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 1 addition & 1 deletion ObjCExample/ObjCExample/MenuItemsTVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation MenuItemsTVC
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView setContentInset:UIEdgeInsetsMake(64.f, 0, 0, 0)];
[self.tableView setBackgroundColor:[UIColor clearColor]];
}

#pragma mark - Table view data source
Expand All @@ -38,7 +39,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
selectionView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3f];
[cell setSelectedBackgroundView:selectionView];
}

cell.textLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row];

return cell;
Expand Down

0 comments on commit 5b2c534

Please sign in to comment.