Skip to content

Commit

Permalink
Adding tap outside to dismiss and public all menu states via delegat
Browse files Browse the repository at this point in the history
  • Loading branch information
luannguyenkhoa-agilityio committed Sep 4, 2017
1 parent ea6a412 commit 8a87da9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Example/LNSideMenu/SMNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class SMNavigationController: LNSideMenuNavigationController {

// Do any additional setup after loading the view.
// Using default side menu
items = ["All","Hot Food","Sandwiches","Hot Pots","Hot Rolls", "Salads","Pies","Dessrts","Drinks","Breakfast","Cookies","Lunch"]
initialSideMenu(.left)
items = ["All","Hot Food","Sandwiches","Hot Pots","Hot Rolls", "Salads","Pies","Dessrts","Drinks","Breakfast","Cookies","Lunch fers"]
// initialSideMenu(.left)
// Custom side menu
// initialCustomMenu(pos: .right)
initialCustomMenu(pos: .right)
}

override func didReceiveMemoryWarning() {
Expand Down
2 changes: 1 addition & 1 deletion Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions LNSideMenu/Classes/LNSideMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public final class LNSideMenu: NSObject, UIGestureRecognizerDelegate {
}
}

open var tapOutsideToDismiss = true
open var disabled: Bool = false
open var enableAnimation: Bool = true
open var customMenu: UIViewController?
Expand Down Expand Up @@ -154,6 +155,9 @@ public final class LNSideMenu: NSObject, UIGestureRecognizerDelegate {
let leftSwipeGesture = pos == .left ? initialSwipeGesture(.right) : initialSwipeGesture(.left)
let rightSwipeGesture = pos == .left ? initialSwipeGesture(.left) : initialSwipeGesture(.right)
handler(leftSwipeGesture, rightSwipeGesture)
/// Tapping outside of sidemenu
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapGesture(gesture:)))
sideMenuContainerView.addGestureRecognizer(tapGesture)
}

// Initialize sidemenu by using default menu
Expand Down Expand Up @@ -321,6 +325,17 @@ public final class LNSideMenu: NSObject, UIGestureRecognizerDelegate {
cacheEnableDynamic = false
toggleMenu((position == .right && gesture.direction == .left) || (position == .left && gesture.direction == .right))
}

internal func tapGesture(gesture: UIGestureRecognizer) {
guard !tapOutsideToDismiss else { return }
if let custom = customMenu?.view {
if custom.frame.contains(gesture.location(in: sideMenuContainerView)) {
toggleMenu()
}
} else {
toggleMenu()
}
}

// MARK: Animations

Expand Down Expand Up @@ -459,10 +474,12 @@ public final class LNSideMenu: NSObject, UIGestureRecognizerDelegate {
centerx = position == .left ? -sourceView.width/2 : sourceView.width + sourceView.width/2
}
isMenuOpen = show
show ? delegate?.sideMenuWillOpen?() : delegate?.sideMenuWillClose?()
UIView.animate(withDuration: animationDuration, animations: {
self.sideMenuContainerView.center.x = centerx
}) { _ in
self.animationCompleted = true
show ? self.delegate?.sideMenuDidOpen?() : self.delegate?.sideMenuDidClose?()
}
// Starting show/hide blur view animation
animateBlurview(isShow: show)
Expand Down
1 change: 1 addition & 0 deletions LNSideMenu/Classes/LNSideMenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ internal final class LNSideMenuView: UIView, UIScrollViewDelegate {
let dest = abs(index-currentIndex)
let sum = (0..<dest).reduce(0, { $0 + $1*kNumberAriProg })
let originX = (right ? 1 : -1) * CGFloat(sum + kNumberDefaultItemsHoziConstant*dest)
print(dest, sum, originX)
let itemFrame = CGRect(x: originX, y: CGFloat(index*Int(kNumberDefaultItemHeight)), width: menusScrollView.width, height: kNumberDefaultItemHeight)

// Initial item by index
Expand Down
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,34 @@
[![License](https://img.shields.io/cocoapods/l/LNSideMenu.svg?style=flat)](http://cocoapods.org/pods/LNSideMenu)
[![Platform](https://img.shields.io/cocoapods/p/LNSideMenu.svg?style=flat)](http://cocoapods.org/pods/LNSideMenu)

SideMenu library that such as a lot of sidemenu libraries on Github for iOS. The main feature of this library: there has a custom menu view that automatically attached as a default menu, but you can use your own menu instead. That menu view was implemented many effects and animations like scrolling effect, fade animation for displaying the menu's items,..
Check it out and explore what it can do.
SideMenu library that such as a lot of sidemenu libraries on Github for iOS.
Besides of basic functions of a SideMenu, there is an enhancement sidemenu that was implemented some effects and animations like scrolling effect, fade animation for displaying the menu's items,..
Checking it out and enjoying.

![Demo](https://cloud.githubusercontent.com/assets/13121441/19177073/0ca0ce0e-8c70-11e6-9e12-d67e7947d98d.gif)
![Demo](https://cloud.githubusercontent.com/assets/13121441/19177074/0cd3415e-8c70-11e6-8082-5057bf406e42.gif)

## Usage

. Create a UINavigationController subclassing from LNSideMenuNavigationController
. Create a UINavigationController subclassed from LNSideMenuNavigationController in order.

. Initilize the menu view with a source view:
. Initilize the menu view based on a source view:
```swift
func initialSideMenu(_ position: Position) {
sideMenu = LNSideMenu(sourceView: view, menuPosition: position, items: items!)
sideMenu?.menuViewController?.menuBgColor = UIColor.black.withAlphaComponent(0.85)
sideMenu?.delegate = self
// Bring navigationBar to front if you want
// Bring navigationBar to front if needed
view.bringSubview(toFront: navigationBar)
}
```
. Implementing delegate methods: didSelectItemAtIndex,..

. In order to change the content viewcontroller: from the your UINavigationController subclassing, getting your destination and then set it as the content viewcontroller.
. In order to change the content viewcontroller: from the your UINavigationController subclass, getting your destination and then making it as the content viewcontroller.

```swift
func didSelectItemAtIndex(index: Int) {
// TODO: Get your destViewController in here
// TODO: Get your destViewController here
self.setContentViewController(destViewController)
}
```
Expand All @@ -42,17 +43,18 @@ self.setContentViewController(destViewController)
self.sideMenuManager?.toggleSideMenuView()
```

. It has a feature for navigation bar translucent. In order to using this feature, just add code as below:
. Making navigation bar translucent by adding these code as following:
```swift
self.navigationBarTranslucentStyle()
sideMenuManager?.sideMenuController()?.sideMenu?.isNavbarHiddenOrTransparent = true
```

. Check example project for more explaination
. Digging `Example` for more explaination

## Using your own menu

Initialize side menu using function
Initialize sidemenu as below in NavigationController subclass:
In order for customizing the menu size in width, we can use one of 3 types of size that consists of full, half and twothird.
```swift
func initialCustomMenu(pos position: Position) {
let menu = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LeftMenuTableViewController") as! LeftMenuTableViewController
Expand All @@ -65,11 +67,8 @@ func initialCustomMenu(pos position: Position) {
sideMenu?.underNavigationBar = true
}
```
in NavigationController subclassing.

There is an argument of this method with default value called ``size``, which is LNSize enum used to set the menu size consits of 3 options: full, half, twothird.

## Custom Properties

## Customizable Properties
```
. disabled: default is false, disabled/enabled sidemenu
. enableDynamic: default is true, disabled/enabled dynamic animator
Expand Down Expand Up @@ -99,7 +98,7 @@ LNSideMenu is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod 'LNSideMenu', '~> 2.2'
pod 'LNSideMenu', '~> 2.3'
```

### Manual
Expand All @@ -112,7 +111,7 @@ Adding all files in LNSideMenu folder to your project folder

## Contribution

I will be happy if anyone's interested in and take the time to contribute it.
I will be much appreciated if anyone's interested in and take your time to contribute it.

## Author

Expand Down

0 comments on commit 8a87da9

Please sign in to comment.