Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a18b99541 | |||
| 7646a77eb5 | |||
| a5c0c537cd | |||
| 31ea1081d1 | |||
| 19ace50017 | |||
| b4105f4c70 | |||
| 092c873849 | |||
| 654501a2f5 | |||
| 27561da4dd | |||
| 12dca5922e | |||
| 3fc2e45ac7 | |||
| 68eb20bd7b | |||
| da2e6d9476 | |||
| 9dfa9cb3ac | |||
| 2565bad185 | |||
| c6ea7979cf | |||
| 78870237e9 | |||
| b09d8d558b | |||
| 0e21162aea | |||
| 347f476296 | |||
| 4828c02cc8 | |||
| 3863fffb7e | |||
| a54bb35fde | |||
| 129fd45f5e |
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yAA-s6-Bam">
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="yAA-s6-Bam">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
|
||||
*/
|
||||
|
||||
public class SideMenuManager {
|
||||
public class SideMenuManager : NSObject {
|
||||
|
||||
public enum MenuPresentMode {
|
||||
@objc public enum MenuPresentMode : Int {
|
||||
case MenuSlideIn
|
||||
case ViewSlideOut
|
||||
case ViewSlideInOut
|
||||
@@ -81,13 +81,19 @@ public class SideMenuManager {
|
||||
/// The right menu swipe to dismiss gesture.
|
||||
public static weak var menuRightSwipeToDismissGesture: UIPanGestureRecognizer?
|
||||
|
||||
/// Enable or disable gestures that would swipe to present or dismiss the menu. Default is true.
|
||||
public static var menuEnableSwipeGestures: Bool = true
|
||||
|
||||
/// Enable or disable interaction with the presenting view controller while the menu is displayed. Enabling may make it difficult to dismiss the menu or cause exceptions if the user tries to present and already presented menu. Default is false.
|
||||
public static var menuPresentingViewControllerUserInteractionEnabled: Bool = false
|
||||
|
||||
/// The strength of the parallax effect on the existing view controller. Does not apply to `menuPresentMode` when set to `ViewSlideOut`. Default is 0.
|
||||
public static var menuParallaxStrength: Int = 0
|
||||
|
||||
/// Draws the `menuAnimationBackgroundColor` behind the status bar. Default is true.
|
||||
public static var menuFadeStatusBar = true
|
||||
|
||||
/// - Warning: Deprecated. Use `menuAnimationTransformScaleFactor` instead.
|
||||
/// -Warning: Deprecated. Use `menuAnimationTransformScaleFactor` instead.
|
||||
@available(*, deprecated, renamed="menuAnimationTransformScaleFactor")
|
||||
public static var menuAnimationShrinkStrength: CGFloat {
|
||||
get {
|
||||
@@ -99,7 +105,7 @@ public class SideMenuManager {
|
||||
}
|
||||
|
||||
// prevent instantiation
|
||||
private init() {}
|
||||
private override init() {}
|
||||
|
||||
/**
|
||||
The blur effect style of the menu if the menu's root view controller is a UITableViewController or UICollectionViewController.
|
||||
|
||||
@@ -17,7 +17,7 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
|
||||
internal static let singleton = SideMenuTransition()
|
||||
internal static var presentDirection: UIRectEdge = .Left;
|
||||
internal static weak var tapView: UIView!
|
||||
internal static weak var tapView: UIView?
|
||||
internal static weak var statusBarView: UIView?
|
||||
|
||||
// prevent instantiation
|
||||
@@ -58,6 +58,10 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
}
|
||||
|
||||
class func handlePresentMenuPan(pan: UIPanGestureRecognizer) {
|
||||
if !SideMenuManager.menuEnableSwipeGestures {
|
||||
return
|
||||
}
|
||||
|
||||
// how much distance have we panned in reference to the parent view?
|
||||
guard let view = viewControllerForPresentedMenu != nil ? viewControllerForPresentedMenu?.view : pan.view else {
|
||||
return
|
||||
@@ -121,6 +125,10 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
}
|
||||
|
||||
class func handleHideMenuPan(pan: UIPanGestureRecognizer) {
|
||||
if !SideMenuManager.menuEnableSwipeGestures {
|
||||
return
|
||||
}
|
||||
|
||||
let translation = pan.translationInView(pan.view!)
|
||||
let direction:CGFloat = SideMenuTransition.presentDirection == .Left ? -1 : 1
|
||||
let distance = translation.x / SideMenuManager.menuWidth * direction
|
||||
@@ -153,13 +161,13 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
|
||||
internal class func hideMenuStart() {
|
||||
NSNotificationCenter.defaultCenter().removeObserver(SideMenuTransition.singleton)
|
||||
|
||||
let mainViewController = SideMenuTransition.viewControllerForPresentedMenu!
|
||||
let menuView = SideMenuTransition.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController!.view : SideMenuManager.menuRightNavigationController!.view
|
||||
guard let mainViewController = SideMenuTransition.viewControllerForPresentedMenu,
|
||||
let menuView = SideMenuTransition.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view else {return}
|
||||
|
||||
menuView.transform = CGAffineTransformIdentity
|
||||
mainViewController.view.transform = CGAffineTransformIdentity
|
||||
mainViewController.view.alpha = 1
|
||||
SideMenuTransition.tapView.frame = CGRectMake(0, 0, mainViewController.view.frame.width, mainViewController.view.frame.height)
|
||||
SideMenuTransition.tapView?.frame = CGRectMake(0, 0, mainViewController.view.frame.width, mainViewController.view.frame.height)
|
||||
menuView.frame.origin.y = 0
|
||||
menuView.frame.size.width = SideMenuManager.menuWidth
|
||||
menuView.frame.size.height = mainViewController.view.frame.height
|
||||
@@ -191,9 +199,12 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
}
|
||||
|
||||
internal class func hideMenuComplete() {
|
||||
let mainViewController = SideMenuTransition.viewControllerForPresentedMenu!
|
||||
let menuView = SideMenuTransition.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController!.view : SideMenuManager.menuRightNavigationController!.view
|
||||
SideMenuTransition.tapView.removeFromSuperview()
|
||||
guard let mainViewController = SideMenuTransition.viewControllerForPresentedMenu,
|
||||
let menuView = SideMenuTransition.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view else {
|
||||
return
|
||||
}
|
||||
|
||||
SideMenuTransition.tapView?.removeFromSuperview()
|
||||
SideMenuTransition.statusBarView?.removeFromSuperview()
|
||||
mainViewController.view.motionEffects.removeAll()
|
||||
mainViewController.view.layer.shadowOpacity = 0
|
||||
@@ -205,11 +216,11 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
}
|
||||
|
||||
internal class func presentMenuStart(forSize size: CGSize = SideMenuManager.appScreenRect.size) {
|
||||
guard let menuView = SideMenuTransition.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view else {
|
||||
return
|
||||
guard let menuView = SideMenuTransition.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view,
|
||||
mainViewController = SideMenuTransition.viewControllerForPresentedMenu else {
|
||||
return
|
||||
}
|
||||
|
||||
let mainViewController = SideMenuTransition.viewControllerForPresentedMenu!
|
||||
menuView.transform = CGAffineTransformIdentity
|
||||
mainViewController.view.transform = CGAffineTransformIdentity
|
||||
menuView.frame.size.width = SideMenuManager.menuWidth
|
||||
@@ -236,7 +247,7 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
menuView.layer.shadowOpacity = SideMenuManager.menuShadowOpacity
|
||||
menuView.layer.shadowOffset = CGSizeMake(0, 0)
|
||||
let direction:CGFloat = SideMenuTransition.presentDirection == .Left ? 1 : -1
|
||||
mainViewController.view.frame.origin.x = direction * (menuView.frame.width)
|
||||
mainViewController.view.frame = CGRect(x: direction * (menuView.frame.width), y: 0, width: size.width, height: size.height)
|
||||
mainViewController.view.transform = CGAffineTransformMakeScale(SideMenuManager.menuAnimationTransformScaleFactor, SideMenuManager.menuAnimationTransformScaleFactor)
|
||||
mainViewController.view.alpha = 1 - SideMenuManager.menuAnimationFadeStrength
|
||||
|
||||
@@ -254,8 +265,10 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
|
||||
internal class func presentMenuComplete() {
|
||||
NSNotificationCenter.defaultCenter().addObserver(SideMenuTransition.singleton, selector:#selector(SideMenuTransition.applicationDidEnterBackgroundNotification), name: UIApplicationDidEnterBackgroundNotification, object: nil)
|
||||
|
||||
let mainViewController = SideMenuTransition.viewControllerForPresentedMenu!
|
||||
guard let mainViewController = SideMenuTransition.viewControllerForPresentedMenu else {
|
||||
return
|
||||
}
|
||||
|
||||
switch SideMenuManager.menuPresentMode {
|
||||
case .MenuSlideIn, .MenuDissolveIn, .ViewSlideInOut:
|
||||
if SideMenuManager.menuParallaxStrength != 0 {
|
||||
@@ -302,15 +315,18 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
|
||||
// prepare menu items to slide in
|
||||
if presenting {
|
||||
let tapView = UIView()
|
||||
tapView.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]
|
||||
let exitPanGesture = UIPanGestureRecognizer()
|
||||
exitPanGesture.addTarget(SideMenuTransition.self, action:#selector(SideMenuTransition.handleHideMenuPan(_:)))
|
||||
let exitTapGesture = UITapGestureRecognizer()
|
||||
exitTapGesture.addTarget(SideMenuTransition.self, action: #selector(SideMenuTransition.handleHideMenuTap(_:)))
|
||||
tapView.addGestureRecognizer(exitPanGesture)
|
||||
tapView.addGestureRecognizer(exitTapGesture)
|
||||
SideMenuTransition.tapView = tapView
|
||||
var tapView: UIView?
|
||||
if !SideMenuManager.menuPresentingViewControllerUserInteractionEnabled {
|
||||
tapView = UIView()
|
||||
tapView!.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]
|
||||
let exitPanGesture = UIPanGestureRecognizer()
|
||||
exitPanGesture.addTarget(SideMenuTransition.self, action:#selector(SideMenuTransition.handleHideMenuPan(_:)))
|
||||
let exitTapGesture = UITapGestureRecognizer()
|
||||
exitTapGesture.addTarget(SideMenuTransition.self, action: #selector(SideMenuTransition.handleHideMenuTap(_:)))
|
||||
tapView!.addGestureRecognizer(exitPanGesture)
|
||||
tapView!.addGestureRecognizer(exitTapGesture)
|
||||
SideMenuTransition.tapView = tapView
|
||||
}
|
||||
|
||||
SideMenuTransition.originalSuperview = topView.superview
|
||||
|
||||
@@ -319,10 +335,14 @@ internal class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewC
|
||||
case .ViewSlideOut:
|
||||
container.addSubview(menuView)
|
||||
container.addSubview(topView)
|
||||
topView.addSubview(tapView)
|
||||
if let tapView = tapView {
|
||||
topView.addSubview(tapView)
|
||||
}
|
||||
case .MenuSlideIn, .MenuDissolveIn, .ViewSlideInOut:
|
||||
container.addSubview(topView)
|
||||
container.addSubview(tapView)
|
||||
if let tapView = tapView {
|
||||
container.addSubview(tapView)
|
||||
}
|
||||
container.addSubview(menuView)
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,11 @@ public class UISideMenuNavigationController: UINavigationController {
|
||||
case .ViewSlideOut, .ViewSlideInOut:
|
||||
mainView.superview?.insertSubview(view, belowSubview: mainView)
|
||||
case .MenuSlideIn, .MenuDissolveIn:
|
||||
mainView.superview?.insertSubview(view, aboveSubview: SideMenuTransition.tapView)
|
||||
if let tapView = SideMenuTransition.tapView {
|
||||
mainView.superview?.insertSubview(view, aboveSubview: tapView)
|
||||
} else {
|
||||
mainView.superview?.insertSubview(view, aboveSubview: mainView)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
[](http://cocoapods.org/pods/SideMenu)
|
||||
[](http://cocoapods.org/pods/SideMenu)
|
||||
|
||||
## Shameless Requests First
|
||||
**1. If you like SideMenu, give it a ★ at the top right of its [GitHub](https://github.com/jonkykong/SideMenu) page.**
|
||||
|
||||
**2. I need an invite to Dribbble to share SideMenu. Invite me: https://dribbble.com/jonkykong**
|
||||
**If you like SideMenu, give it a ★ at the top right of its [GitHub](https://github.com/jonkykong/SideMenu) page.**
|
||||
|
||||
## Overview
|
||||
|
||||
@@ -46,6 +43,9 @@ platform :ios, '8.0'
|
||||
use_frameworks!
|
||||
|
||||
pod 'SideMenu'
|
||||
|
||||
# For Swift 3, use:
|
||||
# pod 'SideMenu', :git => 'https://github.com/jonkykong/SideMenu.git', :branch => 'swift3'
|
||||
```
|
||||
|
||||
Then, run the following command:
|
||||
@@ -97,27 +97,67 @@ That's it.
|
||||
### Customization
|
||||
Just type `SideMenuManager.menu...` and code completion will show you everything you can customize (defaults are shown below for reference):
|
||||
``` swift
|
||||
menuPresentMode:MenuPresentMode = .ViewSlideOut
|
||||
menuAllowPushOfSameClassTwice = true
|
||||
menuAllowPopIfPossible = false
|
||||
menuWidth: CGFloat = max(round(min(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) * 0.75), 240)
|
||||
menuAnimationPresentDuration = 0.35
|
||||
menuAnimationDismissDuration = 0.35
|
||||
menuAnimationFadeStrength: CGFloat = 0
|
||||
menuAnimationTransformScaleFactor: CGFloat = 1
|
||||
menuAnimationBackgroundColor: UIColor? = nil
|
||||
menuShadowOpacity: Float = 0.5
|
||||
menuShadowColor = UIColor.blackColor()
|
||||
menuShadowRadius: CGFloat = 5
|
||||
menuLeftSwipeToDismissGesture: UIPanGestureRecognizer?
|
||||
menuRightSwipeToDismissGesture: UIPanGestureRecognizer?
|
||||
menuParallaxStrength: Int = 0
|
||||
menuFadeStatusBar = true
|
||||
menuBlurEffectStyle: UIBlurEffectStyle? = nil // Note: if you want cells in a UITableViewController menu to look good, make them a subclass of UITableViewVibrantCell!
|
||||
menuLeftNavigationController: UILeftMenuNavigationController? = nil
|
||||
menuRightNavigationController: UIRightMenuNavigationController? = nil
|
||||
menuAddScreenEdgePanGesturesToPresent(toView toView: UIView, forMenu:UIRectEdge? = nil) -> [UIScreenEdgePanGestureRecognizer]
|
||||
menuAddPanGestureToPresent(toView toView: UIView) -> UIPanGestureRecognizer
|
||||
/**
|
||||
The presentation mode of the menu.
|
||||
|
||||
There are four modes in MenuPresentMode:
|
||||
- MenuSlideIn: Menu slides in over of the existing view.
|
||||
- ViewSlideOut: The existing view slides out to reveal the menu.
|
||||
- ViewSlideInOut: The existing view slides out while the menu slides in.
|
||||
- MenuDissolveIn: The menu dissolves in over the existing view controller.
|
||||
*/
|
||||
public static var menuPresentMode: MenuPresentMode = .ViewSlideOut
|
||||
|
||||
/// Prevents the same view controller (or a view controller of the same class) from being pushed more than once. Defaults to true.
|
||||
public static var menuAllowPushOfSameClassTwice = true
|
||||
|
||||
/// Pops to any view controller already in the navigation stack instead of the view controller being pushed if they share the same class. Defaults to false.
|
||||
public static var menuAllowPopIfPossible = false
|
||||
|
||||
/// Width of the menu when presented on screen, showing the existing view controller in the remaining space. Default is 75% of the screen width.
|
||||
public static var menuWidth: CGFloat = max(round(min((appScreenRect.width), (appScreenRect.height)) * 0.75), 240)
|
||||
|
||||
/// Duration of the animation when the menu is presented without gestures. Default is 0.35 seconds.
|
||||
public static var menuAnimationPresentDuration = 0.35
|
||||
|
||||
/// Duration of the animation when the menu is dismissed without gestures. Default is 0.35 seconds.
|
||||
public static var menuAnimationDismissDuration = 0.35
|
||||
|
||||
/// Amount to fade the existing view controller when the menu is presented. Default is 0 for no fade. Set to 1 to fade completely.
|
||||
public static var menuAnimationFadeStrength: CGFloat = 0
|
||||
|
||||
/// The amount to scale the existing view controller or the menu view controller depending on the `menuPresentMode`. Default is 1 for no scaling. Less than 1 will shrink, greater than 1 will grow.
|
||||
public static var menuAnimationTransformScaleFactor: CGFloat = 1
|
||||
|
||||
/// The background color behind menu animations. Depending on the animation settings this may not be visible. If `menuFadeStatusBar` is true, this color is used to fade it. Default is black.
|
||||
public static var menuAnimationBackgroundColor: UIColor?
|
||||
|
||||
/// The shadow opacity around the menu view controller or existing view controller depending on the `menuPresentMode`. Default is 0.5 for 50% opacity.
|
||||
public static var menuShadowOpacity: Float = 0.5
|
||||
|
||||
/// The shadow color around the menu view controller or existing view controller depending on the `menuPresentMode`. Default is black.
|
||||
public static var menuShadowColor = UIColor.blackColor()
|
||||
|
||||
/// The radius of the shadow around the menu view controller or existing view controller depending on the `menuPresentMode`. Default is 5.
|
||||
public static var menuShadowRadius: CGFloat = 5
|
||||
|
||||
/// The left menu swipe to dismiss gesture.
|
||||
public static weak var menuLeftSwipeToDismissGesture: UIPanGestureRecognizer?
|
||||
|
||||
/// The right menu swipe to dismiss gesture.
|
||||
public static weak var menuRightSwipeToDismissGesture: UIPanGestureRecognizer?
|
||||
|
||||
/// Enable or disable gestures that would swipe to present or dismiss the menu. Default is true.
|
||||
public static var menuEnableSwipeGestures: Bool = true
|
||||
|
||||
/// Enable or disable interaction with the presenting view controller while the menu is displayed. Enabling may make it difficult to dismiss the menu or cause exceptions if the user tries to present and already presented menu. Default is false.
|
||||
public static var menuPresentingViewControllerUserInteractionEnabled: Bool = false
|
||||
|
||||
/// The strength of the parallax effect on the existing view controller. Does not apply to `menuPresentMode` when set to `ViewSlideOut`. Default is 0.
|
||||
public static var menuParallaxStrength: Int = 0
|
||||
|
||||
/// Draws the `menuAnimationBackgroundColor` behind the status bar. Default is true.
|
||||
public static var menuFadeStatusBar = true
|
||||
```
|
||||
|
||||
## Known Issues
|
||||
@@ -128,7 +168,7 @@ My name is Jon Kent and I'm a freelance iOS designer, developer, and mobile stra
|
||||
|
||||
🌎 Web: [http://jonkent.me](http://jonkent.me)
|
||||
|
||||
✉️ Email: [contact@jonkent.me](mailto:contact@jonkent.me)
|
||||
✉️ Email: [contact@jonkent.me](mailto:contact@jonkent.me) **_IMPORTANT: If you're having a problem implementing SideMenu, please open an [issue](https://github.com/jonkykong/SideMenu/issues) instead of emailing me. Thanks!_**
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "SideMenu"
|
||||
s.version = "1.1.8"
|
||||
s.version = "1.2.0"
|
||||
s.summary = "Simple side menu control for iOS in Swift inspired by Facebook. Right and Left sides. No coding required."
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
|
||||
Reference in New Issue
Block a user