Compare commits

..

84 Commits

Author SHA1 Message Date
jonkykong 7a30c5441e Updated podspec and README. 2017-06-30 16:50:04 -07:00
jonkykong 13e3d504f1 Added menuDismissOnPush property. 2017-06-30 16:48:19 -07:00
jonkykong 02578a894a Fix for single menu setups losing ability to swipe menu if wrong side is swiped. 2017-06-30 16:45:15 -07:00
jonkykong d31f4419e1 Merge tag '2.3.2'
* tag '2.3.2':
  README edit.
  Updated podspec and README for cocoa pods.

Updated README for Github.
2017-04-26 12:44:34 -07:00
jonkykong 7bf1668184 README edit. 2017-04-26 12:38:24 -07:00
jonkykong e12faa68c9 Updated podspec and README for cocoa pods. 2017-04-26 12:37:10 -07:00
jonkykong ecebaca9b9 Logic correction. 2017-04-26 12:21:58 -07:00
jonkykong aeb660b02f Fix for menu not restoring when background on iPad in iOS 10. 2017-04-26 12:21:45 -07:00
jonkykong e6eb28385c Merge tag '2.3.1'
* tag '2.3.1':
  Updated pod spec and README for Cocoapods.
  Updated project settings.
  Reverting old logic that kept the layout correct when presenting a sub-screen.
  Subtle tweak if a larger transform is used on the main view controller when menu is presented (edge case).
  Fix for disabling gestures. Gestures were being added multiple times preventing all of them from being disabled when the menuEnableSwipeGestures was used.
2017-04-11 03:48:47 -07:00
jonkykong f9f8fd7817 Updated pod spec and README for Cocoapods. 2017-04-11 03:44:32 -07:00
jonkykong dda720eee7 Updated project settings. 2017-04-11 03:41:51 -07:00
jonkykong 8bb2505b6f Reverting old logic that kept the layout correct when presenting a sub-screen. 2017-04-11 03:41:13 -07:00
jonkykong 2878eea03f Subtle tweak if a larger transform is used on the main view controller when menu is presented (edge case). 2017-04-11 03:40:28 -07:00
jonkykong 7512cb9373 Fix for disabling gestures. Gestures were being added multiple times preventing all of them from being disabled when the menuEnableSwipeGestures was used. 2017-04-11 03:35:54 -07:00
Jon Kent 189586d8e8 Update CONTRIBUTING.md 2017-04-04 01:06:08 -07:00
Jon Kent f4d78af501 Update README.md 2017-03-28 11:57:24 -07:00
Jon Kent af2ef21f88 Update README.md 2017-03-26 13:36:39 -07:00
Jon Kent 25b87e4780 Update README.md 2017-03-07 12:23:00 -08:00
jonkykong c966675305 Revert README for Github. 2017-03-06 02:55:15 -08:00
jonkykong b0dfba206c Merge tag '2.3.0'
* tag '2.3.0':
  Updated README and podspec.
  Fix for tapView to not be sized to main screen which may be transformed and therefor hard to touch.
  Support for in-call status bar height change.
  Refactoring.
  Updated demo project to show various SideMenu events.
  Logic simplification.
  Removal of no longer needed logic.
  Updated comments and minor refactor.
  Fix for keyboard animations being confused during SideMenu display.
  Updated documentation.
  Fix deprecation warnings in swift 3.1
2017-03-06 02:54:35 -08:00
jonkykong 8960d3b4df Updated README and podspec. 2017-03-06 02:48:18 -08:00
jonkykong 05a117655b Fix for tapView to not be sized to main screen which may be transformed and therefor hard to touch. 2017-03-06 02:42:37 -08:00
jonkykong 5ed24a978e Support for in-call status bar height change. 2017-03-06 02:41:24 -08:00
jonkykong 330ea36ce5 Refactoring. 2017-03-06 02:40:06 -08:00
jonkykong 05d934d084 Updated demo project to show various SideMenu events. 2017-03-06 02:00:05 -08:00
jonkykong a520e98dbe Logic simplification. 2017-03-06 01:59:13 -08:00
jonkykong e49d564a2f Removal of no longer needed logic. 2017-03-06 01:57:00 -08:00
jonkykong 632c35509b Updated comments and minor refactor. 2017-03-06 01:56:07 -08:00
jonkykong b0a40b6fcf Fix for keyboard animations being confused during SideMenu display. 2017-03-06 01:55:00 -08:00
jonkykong 3d86c530ee Updated documentation. 2017-03-06 01:53:49 -08:00
Josh Friend 4983a468c5 Fix deprecation warnings in swift 3.1 2017-02-17 08:41:31 -05:00
Jon Kent bfbe4d21bf Update README.md 2017-02-13 12:04:40 -08:00
Jon Kent 615ff0e391 Update ISSUE_TEMPLATE.md 2017-02-07 23:35:10 -08:00
Jon Kent bdb9e4b3ae Update README.md 2017-02-04 19:30:54 -08:00
Jon Kent 1c7d834c63 Update CONTRIBUTING.md 2017-01-30 16:02:46 -08:00
Jon Kent 2e5ee04587 Update CONTRIBUTING.md 2017-01-30 04:20:31 -08:00
Jon Kent 806a7dd1c7 Update CONTRIBUTING.md 2017-01-29 14:10:34 -08:00
Jon Kent 094586042f Update CONTRIBUTING.md 2017-01-29 14:00:45 -08:00
Jon Kent e919cd5b56 Update README.md 2017-01-27 11:18:43 -08:00
Jon Kent e79169e735 Update README.md 2017-01-26 13:57:46 -08:00
Jon Kent a43fbb64f8 Update README.md 2017-01-25 23:20:52 -08:00
Jon Kent 275e01bdfd Update README.md 2017-01-25 22:48:09 -08:00
jonkykong 98da8fefc1 Update README for Github. 2017-01-24 21:40:17 -08:00
jonkykong b68fa60439 Merge tag '2.2.0'
* tag '2.2.0': (23 commits)
  Remove unused variable.
  Update README for Cocoapods.
  Update podspec.
  Updated README.
  Update comment.
  Additional debug warnings to help troubleshoot common problems.
  Refactoring.
  Tighter logic for responding to only a single gesture to avoid conflicts.
  New properties for further customizing non-interactive menu animations.
  Some refactoring and added in .subMenu to the list of behaviors.
  Documentation - added note about .replace hiding the back button.
  deprecation function simplification for .replace and .popifpossible
  updated readme and fixed indentation issues
  Enum changed / new "hide back button" behaviors
  updated documentation (disables back button)
  Default for "PreserveViewOnPush" is now to always disable the back button.
  When I thought I included the animation in the last commit, I did it in my own test project lol 00ps. Animation default now included as well as disable nav back button.
  removed menuTab option and set default action to always hide SideMenu when transitioning to new view. Refactored menuPreserveViewOnPush to match syntax and efficiency
  implemented changed to menuPreserveViewOnPush filter, now instead matching syntax with type(of: )
  last indentation fix
  ...
2017-01-24 21:39:42 -08:00
jonkykong 8f4e9ee214 Remove unused variable. 2017-01-24 21:31:42 -08:00
jonkykong bac8e1591d Update README for Cocoapods. 2017-01-24 21:27:31 -08:00
jonkykong 4ed14e7856 Update podspec. 2017-01-24 21:25:07 -08:00
jonkykong 60157eb001 Updated README. 2017-01-24 21:24:50 -08:00
jonkykong 743deb7e03 Update comment. 2017-01-24 21:23:58 -08:00
jonkykong 8f26bbb2d9 Additional debug warnings to help troubleshoot common problems. 2017-01-24 21:20:27 -08:00
jonkykong 192ef476bd Refactoring. 2017-01-24 21:19:59 -08:00
jonkykong 8fbf4002ac Tighter logic for responding to only a single gesture to avoid conflicts. 2017-01-24 21:19:26 -08:00
jonkykong 63e0b2b11b New properties for further customizing non-interactive menu animations. 2017-01-24 21:17:52 -08:00
jonkykong f371f0a7ee Merge branch 'pr/135' into 2.2.0
* pr/135:
  Some refactoring and added in .subMenu to the list of behaviors.
  Documentation - added note about .replace hiding the back button.
  deprecation function simplification for .replace and .popifpossible
  updated readme and fixed indentation issues
  Enum changed / new "hide back button" behaviors
  updated documentation (disables back button)
  Default for "PreserveViewOnPush" is now to always disable the back button.
  When I thought I included the animation in the last commit, I did it in my own test project lol 00ps. Animation default now included as well as disable nav back button.
  removed menuTab option and set default action to always hide SideMenu when transitioning to new view. Refactored menuPreserveViewOnPush to match syntax and efficiency
  implemented changed to menuPreserveViewOnPush filter, now instead matching syntax with type(of: )
  last indentation fix
  more stupid indentation issues fixed
  fixed spacing / indentation issues
  forked and added changes (tab feature and restore view controller feature)
2017-01-24 21:15:36 -08:00
jonkykong fbb692cd61 Some refactoring and added in .subMenu to the list of behaviors. 2017-01-24 21:14:55 -08:00
Jon Kent 78e6655363 Update README.md 2017-01-23 11:15:13 -08:00
Jon Kent a18d25d409 Update README.md 2017-01-23 10:36:27 -08:00
Jon Kent 422fbb72b0 Update ISSUE_TEMPLATE.md 2017-01-22 14:13:26 -08:00
Jon Kent adb5f861e4 Update CONTRIBUTING.md 2017-01-22 13:59:42 -08:00
Jon Kent 89d724cca0 Update README.md 2017-01-20 17:14:32 -08:00
agates4 08145abacb Documentation - added note about .replace hiding the back button. 2017-01-20 18:59:38 -05:00
agates4 b37bae8a02 deprecation function simplification for .replace and .popifpossible 2017-01-20 18:52:20 -05:00
agates4 52960fac95 updated readme and fixed indentation issues 2017-01-20 18:50:04 -05:00
agates4 72d998b184 Enum changed / new "hide back button" behaviors 2017-01-20 18:40:46 -05:00
Jon Kent f29ad608f7 Update README.md 2017-01-20 14:57:06 -08:00
Jon Kent 3ff92c69e6 Update README.md 2017-01-20 14:55:38 -08:00
agates4 c3a50dac9b updated documentation (disables back button) 2017-01-20 13:57:02 -05:00
agates4 93dacf7b1d Default for "PreserveViewOnPush" is now to always disable the back button. 2017-01-20 13:54:47 -05:00
agates4 5ff4caff44 When I thought I included the animation in the last commit, I did it in my own test project lol 00ps. Animation default now included as well as disable nav back button. 2017-01-20 13:53:16 -05:00
agates4 4656a951a2 removed menuTab option and set default action to always hide SideMenu when transitioning to new view. Refactored menuPreserveViewOnPush to match syntax and efficiency 2017-01-19 16:54:20 -05:00
agates4 18e1f751e8 implemented changed to menuPreserveViewOnPush filter, now instead matching syntax with type(of: ) 2017-01-19 15:21:30 -05:00
agates4 513d9603b2 last indentation fix 2017-01-19 14:26:25 -05:00
agates4 142d57e84c more stupid indentation issues fixed 2017-01-19 14:25:46 -05:00
agates4 f15081a31b fixed spacing / indentation issues 2017-01-19 14:23:47 -05:00
agates4 4c04c841c3 forked and added changes (tab feature and restore view controller feature) 2017-01-19 14:18:58 -05:00
jonkykong f6bf6972e9 Update README for GitHub. 2017-01-12 14:21:30 -08:00
jonkykong 02f643a667 Merge tag '2.1.5'
* tag '2.1.5':
  Update README for Cocoapods.
  Update pod spec.
  Refactoring.
  Second fix for multiple gestures actuating and causing problem.
2017-01-12 14:20:44 -08:00
jonkykong a1716035c3 Update README for Cocoapods. 2017-01-12 14:17:04 -08:00
jonkykong 99456afaed Update pod spec. 2017-01-12 14:16:49 -08:00
jonkykong 4b92f5a776 Refactoring. 2017-01-12 14:14:05 -08:00
jonkykong 459a4a1e9f Second fix for multiple gestures actuating and causing problem. 2017-01-12 14:13:43 -08:00
jonkykong 717fd3a325 Update README for GitHub. 2017-01-10 13:13:59 -08:00
jonkykong 802146708e Merge tag '2.1.4'
* tag '2.1.4':
  Silence warning.
  Update README for Cocoapods.
  Update podspec.
  Fix for multiple gestures causing crashes when presenting or dismissing menu. SideMenuTransition is due for a refactoring of logic to simplify that I don’t have time for now.
  Update to Launch Screen.
  Say “SideMenu” instead of “Example” in demo project.
2017-01-10 13:13:04 -08:00
jonkykong f34452d040 Updating README for GitHub. 2017-01-09 12:49:17 -08:00
11 changed files with 491 additions and 205 deletions
+12 -6
View File
@@ -4,14 +4,20 @@ Thank you for your interest in SideMenu!
I have received a surprising amount of questions about SideMenu since putting it up here. A few people in the community have identified some problems and helped contribute to SideMenu to make it better for everyone and I'm truly grateful for the support! Keep them coming!
I have also received a number of questions about people having issues implementing SideMenu, mostly from beginners learning how to code. As much as I would love to help all of you, I simply do **not** have the time to teach you. That's why I spent a lot of time putting together a detailed [README](https://github.com/jonkykong/SideMenu/blob/master/README.md), adding comments about usage in code, and providing a [demo project](https://github.com/jonkykong/SideMenu/tree/master/Example). These will give you all the information you need to work through any problem and also save me the time it takes to personally respond. **It is faster for you to figure it out for yourself instead of waiting for me to respond to you.**
I have also received a number of questions about people having issues implementing SideMenu, mostly from beginners learning how to code. As much as I would love to help all of you, **I do not have time to teach you**. I am only supporting bugfixes or reviewing pull requests.
I spent a lot of time putting together a detailed [README](https://github.com/jonkykong/SideMenu/blob/master/README.md), adding comments about usage in code, and provided a [demo project](https://github.com/jonkykong/SideMenu/tree/master/Example). These will give you all the information you need to work through any problem, **saving _you_ the time it takes for me to personally respond.**
### If your question begins with _"How do I..."_
- It's **not** a bug. Stay persistent, try a few different things, and you will figure it out! I also recommend searching and posting your questions on [stackoverflow.com](stackoverflow.com). Or, if you're interested in hiring me to teach you, please email me using the email address listed at the top of my [README](https://github.com/jonkykong/SideMenu/blob/master/README.md).
- That's **not** a bug. Go back through the [README](https://github.com/jonkykong/SideMenu/blob/master/README.md). Check out the [demo project](https://github.com/jonkykong/SideMenu/tree/master/Example). Stay persistent, try a few different things, and you will figure it out! **It is generally faster for you to figure it out for yourself instead of waiting for me to respond to you.** I also recommend searching and posting your questions on [stackoverflow.com](stackoverflow.com). If you're interested in hiring me to teach you, please email me using the email address listed at the top of my [README](https://github.com/jonkykong/SideMenu/blob/master/README.md).
### If your question begins with _"Can I..."_
- That's a **new feature request**. I am no longer investing my personal time to implement one-off features because SideMenu currently meets the majority of people's needs with the features it already has. However, this is a great opportunity for you to contribute to this open source project! Feel free to open an issue to ask any clarifying questions for your new feature before you start building. Open a [pull request](https://github.com/jonkykong/SideMenu/pull/new/master) when you're ready for me to merge it.
### If your question begins with _"How can I..."_
- That's a **new feature request**. I am no longer investing my personal time to implement one-off features because SideMenu currently meets the majority of people's needs with the features it already has. However, this is a great opportunity for you to [join the proud members](https://github.com/jonkykong/SideMenu/graphs/contributors) who have contributed to this open source project! Feel free to open an issue to ask any clarifying questions for your new feature before you start building. Open a [pull request](https://github.com/jonkykong/SideMenu/pull/new/master) when you're ready for me to merge it.
**Again**, please do **not** email me or open any issues if you want to know how to use SideMenu or are having trouble getting it to work. However, if you think you found a bug, open an issue and I will respond to it as quickly as I can. You should be able to demonstrate the bug in the [demo project](https://github.com/jonkykong/SideMenu/tree/master/Example) which has a minimal amount of code.
### If your question is about SideMenu not working the way it's described in the [README](https://github.com/jonkykong/SideMenu/blob/master/README.md)...
- This *may* be a bug. You must be able to reproduce the bug in the [demo project](https://github.com/jonkykong/SideMenu/tree/master/Example) which has a minimal amount of code. This helps ensure you don't have a bug in your code unrelated to SideMenu. If the bug is reproducable, open an issue and I will respond to it when I find time.
Thanks again for your support and for being respectful of my time.
**Again**, please do **not** email me or open any issues if you want to know how to use SideMenu or are having trouble getting it to behave a specific way not described in the [README](https://github.com/jonkykong/SideMenu/blob/master/README.md). I am not **tech support**. I am not a **teacher**. If you open an issue while failing to follow these guidelines or use the provided templates your **request for help will be ignored**.
### Thanks again for your support and for being respectful of my time.
I apologize if this seems harsh, but there have been too many developers that have willfully ignored all of this and continued to contact me.
+2 -1
View File
@@ -1,8 +1,9 @@
<!--- Provide a general summary of your changes in the Title above -->
<!--- IF YOU DELETE OR IGNORE THIS TEMPLATE WHEN OPENING A NEW ISSUE, YOUR ISSUE WILL BE IGNORED -->
## New Issue Checklist
<!--- Please complete all of the checks below before submitting a new issue -->
<!--- Please complete all of the checks below before submitting a new issue (complete a check by marking it [x] with no spaces) -->
I have read the [guidelines for contributing](https://github.com/jonkykong/SideMenu/blob/master/.github/CONTRIBUTING.md) and I understand:
- [ ] My issue is happening in the **latest version** of SideMenu.
- [ ] My issue was **not** solved in the [README](https://github.com/jonkykong/SideMenu/blob/master/README.md).
- [ ] My issue can **not** be answered on [stackoverflow.com](stackoverflow.com).
- [ ] My issue is **not** a request for new functionality that I am unwilling to build and contribute with a pull request.
+2 -2
View File
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="yAA-s6-Bam">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="yAA-s6-Bam">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
+21
View File
@@ -14,6 +14,8 @@ class SideMenuTableView: UITableViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("SideMenu Appearing!")
// this will be non-nil if a blur effect is applied
guard tableView.backgroundView == nil else {
return
@@ -25,4 +27,23 @@ class SideMenuTableView: UITableViewController {
imageView.backgroundColor = UIColor.black.withAlphaComponent(0.2)
tableView.backgroundView = imageView
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("SideMenu Appeared!")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("SideMenu Disappearing!")
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
print("SideMenu Disappeared!")
}
}
+122 -21
View File
@@ -18,11 +18,20 @@
open class SideMenuManager : NSObject {
@objc public enum MenuPushStyle : Int {
case defaultBehavior,
popWhenPossible,
replace,
preserve,
preserveAndHideBackButton,
subMenu
}
@objc public enum MenuPresentMode : Int {
case menuSlideIn
case viewSlideOut
case viewSlideInOut
case menuDissolveIn
case menuSlideIn,
viewSlideOut,
viewSlideInOut,
menuDissolveIn
}
// Bounds which has been allocated for the app on the whole device screen
@@ -31,6 +40,19 @@ open class SideMenuManager : NSObject {
return appWindowRect
}
/**
The push style of the menu.
There are six modes in MenuPushStyle:
- defaultBehavior: The view controller is pushed onto the stack.
- popWhenPossible: If a view controller already in the stack is of the same class as the pushed view controller, the stack is instead popped back to the existing view controller. This behavior can help users from getting lost in a deep navigation stack.
- preserve: If a view controller already in the stack is of the same class as the pushed view controller, the existing view controller is pushed to the end of the stack. This behavior is similar to a UITabBarController.
- preserveAndHideBackButton: Same as .preserve and back buttons are automatically hidden.
- replace: Any existing view controllers are released from the stack and replaced with the pushed view controller. Back buttons are automatically hidden. This behavior is ideal if view controllers require a lot of memory or their state doesn't need to be preserved..
- subMenu: Unlike all other behaviors that push using the menu's presentingViewController, this behavior pushes view controllers within the menu. Use this behavior if you want to display a sub menu.
*/
open static var menuPushStyle: MenuPushStyle = .defaultBehavior
/**
The presentation mode of the menu.
@@ -45,17 +67,17 @@ open class SideMenuManager : NSObject {
/// Prevents the same view controller (or a view controller of the same class) from being pushed more than once. Defaults to true.
open 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.
open 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.
open 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.
open static var menuAnimationPresentDuration = 0.35
open static var menuAnimationPresentDuration: Double = 0.35
/// Duration of the animation when the menu is dismissed without gestures. Default is 0.35 seconds.
open static var menuAnimationDismissDuration = 0.35
open static var menuAnimationDismissDuration: Double = 0.35
/// Duration of the remaining animation when the menu is partially dismissed with gestures. Default is 0.2 seconds.
open static var menuAnimationCompleteGestureDuration: Double = 0.20
/// Amount to fade the existing view controller when the menu is presented. Default is 0 for no fade. Set to 1 to fade completely.
open static var menuAnimationFadeStrength: CGFloat = 0
@@ -75,12 +97,6 @@ open class SideMenuManager : NSObject {
/// The radius of the shadow around the menu view controller or existing view controller depending on the `menuPresentMode`. Default is 5.
open static var menuShadowRadius: CGFloat = 5
/// The left menu swipe to dismiss gesture.
open static weak var menuLeftSwipeToDismissGesture: UIPanGestureRecognizer?
/// The right menu swipe to dismiss gesture.
open static weak var menuRightSwipeToDismissGesture: UIPanGestureRecognizer?
/// 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.
open static var menuPresentingViewControllerUserInteractionEnabled: Bool = false
@@ -90,11 +106,61 @@ open class SideMenuManager : NSObject {
/// Draws the `menuAnimationBackgroundColor` behind the status bar. Default is true.
open static var menuFadeStatusBar = true
/// When true, pushViewController called within the menu it will push the new view controller inside of the menu. Otherwise, it is pushed on the menu's presentingViewController. Default is false.
open static var menuAllowSubmenus: Bool = false
/// The animation options when a menu is displayed. Ignored when displayed with a gesture.
open static var menuAnimationOptions: UIViewAnimationOptions = .curveEaseInOut
/// When true, pushViewController will replace the last view controller in the navigation controller's viewController stack instead of appending to it. This makes menus similar to tab bar controller behavior.
open static var menuReplaceOnPush: Bool = false
/// The animation spring damping when a menu is displayed. Ignored when displayed with a gesture.
open static var menuAnimationUsingSpringWithDamping: CGFloat = 1
/// The animation initial spring velocity when a menu is displayed. Ignored when displayed with a gesture.
open static var menuAnimationInitialSpringVelocity: CGFloat = 1
/**
Automatically dismisses the menu when another view is pushed from it.
Note: to prevent the menu from dismissing when presenting, set modalPresentationStyle = .overFullScreen
of the view controller being presented in storyboard or during its initalization.
*/
open static var menuDismissOnPush = true
/// -Warning: Deprecated. Use `menuPushStyle = .subMenu` instead.
@available(*, deprecated, renamed: "menuPushStyle", message: "Use `menuPushStyle = .subMenu` instead.")
open static var menuAllowSubmenus: Bool {
get {
return menuPushStyle == .subMenu
}
set {
if newValue {
menuPushStyle = .subMenu
}
}
}
/// -Warning: Deprecated. Use `menuPushStyle = .popWhenPossible` instead.
@available(*, deprecated, renamed: "menuPushStyle", message: "Use `menuPushStyle = .popWhenPossible` instead.")
open static var menuAllowPopIfPossible: Bool {
get {
return menuPushStyle == .popWhenPossible
}
set {
if newValue {
menuPushStyle = .popWhenPossible
}
}
}
/// -Warning: Deprecated. Use `menuPushStyle = .replace` instead.
@available(*, deprecated, renamed: "menuPushStyle", message: "Use `menuPushStyle = .replace` instead.")
open static var menuReplaceOnPush: Bool {
get {
return menuPushStyle == .replace
}
set {
if newValue {
menuPushStyle = .replace
}
}
}
/// -Warning: Deprecated. Use `menuAnimationTransformScaleFactor` instead.
@available(*, deprecated, renamed: "menuAnimationTransformScaleFactor")
@@ -157,6 +223,30 @@ open class SideMenuManager : NSObject {
}
}
/// The left menu swipe to dismiss gesture.
open static weak var menuLeftSwipeToDismissGesture: UIPanGestureRecognizer? {
didSet {
oldValue?.view?.removeGestureRecognizer(oldValue!)
setupGesture(gesture: menuLeftSwipeToDismissGesture)
}
}
/// The right menu swipe to dismiss gesture.
open static weak var menuRightSwipeToDismissGesture: UIPanGestureRecognizer? {
didSet {
oldValue?.view?.removeGestureRecognizer(oldValue!)
setupGesture(gesture: menuRightSwipeToDismissGesture)
}
}
fileprivate class func setupGesture(gesture: UIPanGestureRecognizer?) {
guard let gesture = gesture else {
return
}
gesture.addTarget(SideMenuTransition.self, action:#selector(SideMenuTransition.handleHideMenuPan(_:)))
}
fileprivate class func setupNavigationController(_ forMenu: UISideMenuNavigationController?, leftSide: Bool) {
guard let forMenu = forMenu else {
return
@@ -164,7 +254,6 @@ open class SideMenuManager : NSObject {
if menuEnableSwipeGestures {
let exitPanGesture = UIPanGestureRecognizer()
exitPanGesture.addTarget(SideMenuTransition.self, action:#selector(SideMenuTransition.handleHideMenuPan(_:)))
forMenu.view.addGestureRecognizer(exitPanGesture)
if leftSide {
menuLeftSwipeToDismissGesture = exitPanGesture
@@ -178,7 +267,7 @@ open class SideMenuManager : NSObject {
updateMenuBlurIfNecessary()
}
/// Enable or disable gestures that would swipe to present or dismiss the menu. Default is true.
/// Enable or disable gestures that would swipe to dismiss the menu. Default is true.
open static var menuEnableSwipeGestures: Bool = true {
didSet {
menuLeftSwipeToDismissGesture?.view?.removeGestureRecognizer(menuLeftSwipeToDismissGesture!)
@@ -264,6 +353,10 @@ open class SideMenuManager : NSObject {
leftScreenEdgeGestureRecognizer.cancelsTouchesInView = true
toView.addGestureRecognizer(leftScreenEdgeGestureRecognizer)
array.append(leftScreenEdgeGestureRecognizer)
if SideMenuManager.menuLeftNavigationController == nil {
print("SideMenu Warning: menuAddScreenEdgePanGesturesToPresent for the left side was called before menuLeftNavigationController has been defined. The gesture will not work without a menu.")
}
}
if forMenu != .left {
@@ -273,6 +366,10 @@ open class SideMenuManager : NSObject {
rightScreenEdgeGestureRecognizer.cancelsTouchesInView = true
toView.addGestureRecognizer(rightScreenEdgeGestureRecognizer)
array.append(rightScreenEdgeGestureRecognizer)
if SideMenuManager.menuRightNavigationController == nil {
print("SideMenu Warning: menuAddScreenEdgePanGesturesToPresent for the right side was called before menuRightNavigationController has been defined. The gesture will not work without a menu.")
}
}
return array
@@ -290,6 +387,10 @@ open class SideMenuManager : NSObject {
panGestureRecognizer.addTarget(SideMenuTransition.self, action:#selector(SideMenuTransition.handlePresentMenuPan(_:)))
toView.addGestureRecognizer(panGestureRecognizer)
if SideMenuManager.menuLeftNavigationController ?? SideMenuManager.menuRightNavigationController == nil {
print("SideMenu Warning: menuAddPanGestureToPresent called before menuLeftNavigationController or menuRightNavigationController have been defined. Gestures will not work without a menu.")
}
return panGestureRecognizer
}
}
+192 -103
View File
@@ -8,15 +8,16 @@
import UIKit
open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {
open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
fileprivate var presenting = false
fileprivate var interactive = false
fileprivate static weak var originalSuperview: UIView?
fileprivate static weak var activeGesture: UIGestureRecognizer?
fileprivate static var switchMenus = false
internal static let singleton = SideMenuTransition()
internal static var presentDirection: UIRectEdge = .left;
internal static var presentDirection: UIRectEdge = .left
internal static weak var tapView: UIView? {
didSet {
guard let tapView = tapView else {
@@ -48,11 +49,25 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
}
// prevent instantiation
fileprivate override init() {}
fileprivate override init() {
super.init()
NotificationCenter.default.addObserver(self, selector:#selector(SideMenuTransition.handleNotification), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
NotificationCenter.default.addObserver(self, selector:#selector(SideMenuTransition.handleNotification), name: NSNotification.Name.UIApplicationWillChangeStatusBarFrame, object: nil)
}
fileprivate class var viewControllerForPresentedMenu: UIViewController? {
deinit {
NotificationCenter.default.removeObserver(SideMenuTransition.singleton)
}
fileprivate class var presentingViewControllerForMenu: UIViewController? {
get {
return SideMenuManager.menuLeftNavigationController?.presentingViewController != nil ? SideMenuManager.menuLeftNavigationController?.presentingViewController : SideMenuManager.menuRightNavigationController?.presentingViewController
return SideMenuManager.menuLeftNavigationController?.presentingViewController ?? SideMenuManager.menuRightNavigationController?.presentingViewController
}
}
fileprivate class var viewControllerForMenu: UISideMenuNavigationController? {
get {
return SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController
}
}
@@ -85,13 +100,23 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
}
internal class func handlePresentMenuPan(_ pan: UIPanGestureRecognizer) {
if activeGesture == nil {
activeGesture = pan
} else if pan != activeGesture {
pan.isEnabled = false
pan.isEnabled = true
return
} else if pan.state != .began && pan.state != .changed {
activeGesture = nil
}
// how much distance have we panned in reference to the parent view?
guard let view = viewControllerForPresentedMenu != nil ? viewControllerForPresentedMenu?.view : pan.view else {
guard let view = presentingViewControllerForMenu?.view ?? pan.view else {
return
}
let transform = view.transform
view.transform = CGAffineTransform.identity
view.transform = .identity
let translation = pan.translation(in: pan.view!)
view.transform = transform
@@ -105,10 +130,11 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
SideMenuTransition.presentDirection = translation.x > 0 ? .left : .right
}
if let menuViewController = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController,
let visibleViewController = visibleViewController {
if let menuViewController = viewControllerForMenu, let visibleViewController = visibleViewController {
singleton.interactive = true
visibleViewController.present(menuViewController, animated: true, completion: nil)
} else {
return
}
}
@@ -132,12 +158,12 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
}
default:
singleton.interactive = false
view.transform = CGAffineTransform.identity
view.transform = .identity
let velocity = pan.velocity(in: pan.view!).x * direction
view.transform = transform
if velocity >= 100 || velocity >= -50 && abs(distance) >= 0.5 {
// bug workaround: animation briefly resets after call to finishInteractiveTransition() but before animateTransition completion is called.
if ProcessInfo().operatingSystemVersion.majorVersion == 8 && singleton.percentComplete > 1 - CGFloat(FLT_EPSILON) {
if ProcessInfo().operatingSystemVersion.majorVersion == 8 && singleton.percentComplete > 1 - CGFloat.ulpOfOne {
singleton.update(0.9999)
}
singleton.finish()
@@ -148,6 +174,14 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
}
internal class func handleHideMenuPan(_ pan: UIPanGestureRecognizer) {
if activeGesture == nil {
activeGesture = pan
} else if pan != activeGesture {
pan.isEnabled = false
pan.isEnabled = true
return
}
let translation = pan.translation(in: pan.view!)
let direction:CGFloat = SideMenuTransition.presentDirection == .left ? -1 : 1
let distance = translation.x / SideMenuManager.menuWidth * direction
@@ -156,7 +190,7 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
case .began:
singleton.interactive = true
viewControllerForPresentedMenu?.dismiss(animated: true, completion: nil)
presentingViewControllerForMenu?.dismiss(animated: true, completion: nil)
case .changed:
singleton.update(max(min(distance, 1), 0))
default:
@@ -164,35 +198,43 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
let velocity = pan.velocity(in: pan.view!).x * direction
if velocity >= 100 || velocity >= -50 && distance >= 0.5 {
// bug workaround: animation briefly resets after call to finishInteractiveTransition() but before animateTransition completion is called.
if ProcessInfo().operatingSystemVersion.majorVersion == 8 && singleton.percentComplete > 1 - CGFloat(FLT_EPSILON) {
if ProcessInfo().operatingSystemVersion.majorVersion == 8 && singleton.percentComplete > 1 - CGFloat.ulpOfOne {
singleton.update(0.9999)
}
singleton.finish()
activeGesture = nil
} else {
singleton.cancel()
activeGesture = nil
}
}
}
internal class func handleHideMenuTap(_ tap: UITapGestureRecognizer) {
viewControllerForPresentedMenu?.dismiss(animated: true, completion: nil)
presentingViewControllerForMenu?.dismiss(animated: true, completion: nil)
}
internal class func hideMenuStart() {
NotificationCenter.default.removeObserver(SideMenuTransition.singleton)
guard let mainViewController = SideMenuTransition.viewControllerForPresentedMenu,
guard let mainViewController = presentingViewControllerForMenu,
let menuView = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view else {
return
}
menuView.transform = CGAffineTransform.identity
mainViewController.view.transform = CGAffineTransform.identity
mainViewController.view.transform = .identity
mainViewController.view.alpha = 1
SideMenuTransition.tapView?.frame = CGRect(x: 0, y: 0, width: mainViewController.view.frame.width, height: mainViewController.view.frame.height)
mainViewController.view.frame.origin.y = 0
menuView.transform = .identity
menuView.frame.origin.y = 0
menuView.frame.size.width = SideMenuManager.menuWidth
menuView.frame.size.height = mainViewController.view.frame.height
SideMenuTransition.statusBarView?.frame = UIApplication.shared.statusBarFrame
menuView.frame.size.height = mainViewController.view.frame.height // in case status bar height changed
var statusBarFrame = UIApplication.shared.statusBarFrame
let statusBarOffset = SideMenuManager.appScreenRect.size.height - mainViewController.view.frame.maxY
// For in-call status bar, height is normally 40, which overlaps view. Instead, calculate height difference
// of view and set height to fill in remaining space.
if statusBarOffset >= CGFloat.ulpOfOne {
statusBarFrame.size.height = statusBarOffset
}
SideMenuTransition.statusBarView?.frame = statusBarFrame
SideMenuTransition.statusBarView?.alpha = 0
switch SideMenuManager.menuPresentMode {
@@ -220,8 +262,8 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
}
internal class func hideMenuComplete() {
guard let mainViewController = SideMenuTransition.viewControllerForPresentedMenu,
let menuView = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view else {
guard let mainViewController = presentingViewControllerForMenu,
let menuView = viewControllerForMenu?.view else {
return
}
@@ -233,62 +275,71 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
if let topNavigationController = mainViewController as? UINavigationController {
topNavigationController.interactivePopGestureRecognizer!.isEnabled = true
}
originalSuperview?.addSubview(mainViewController.view)
if let originalSuperview = originalSuperview {
originalSuperview.addSubview(mainViewController.view)
let y = originalSuperview.bounds.height - mainViewController.view.frame.size.height
mainViewController.view.frame.origin.y = max(y, 0)
}
}
internal class func presentMenuStart(forSize size: CGSize = SideMenuManager.appScreenRect.size) {
guard let menuView = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController?.view : SideMenuManager.menuRightNavigationController?.view,
let mainViewController = SideMenuTransition.viewControllerForPresentedMenu else {
internal class func presentMenuStart() {
guard let menuView = viewControllerForMenu?.view,
let mainViewController = presentingViewControllerForMenu else {
return
}
menuView.transform = CGAffineTransform.identity
mainViewController.view.transform = CGAffineTransform.identity
menuView.alpha = 1
menuView.transform = .identity
menuView.frame.size.width = SideMenuManager.menuWidth
menuView.frame.size.height = size.height
let size = SideMenuManager.appScreenRect.size
menuView.frame.origin.x = SideMenuTransition.presentDirection == .left ? 0 : size.width - SideMenuManager.menuWidth
SideMenuTransition.statusBarView?.frame = UIApplication.shared.statusBarFrame
mainViewController.view.transform = .identity
mainViewController.view.frame.size.width = size.width
let statusBarOffset = size.height - menuView.bounds.height
mainViewController.view.bounds.size.height = size.height - max(statusBarOffset, 0)
mainViewController.view.frame.origin.y = 0
var statusBarFrame = UIApplication.shared.statusBarFrame
// For in-call status bar, height is normally 40, which overlaps view. Instead, calculate height difference
// of view and set height to fill in remaining space.
if statusBarOffset >= CGFloat.ulpOfOne {
statusBarFrame.size.height = statusBarOffset
}
SideMenuTransition.tapView?.transform = .identity
SideMenuTransition.tapView?.bounds = mainViewController.view.bounds
SideMenuTransition.statusBarView?.frame = statusBarFrame
SideMenuTransition.statusBarView?.alpha = 1
switch SideMenuManager.menuPresentMode {
case .viewSlideOut:
menuView.alpha = 1
case .viewSlideOut, .viewSlideInOut:
mainViewController.view.layer.shadowColor = SideMenuManager.menuShadowColor.cgColor
mainViewController.view.layer.shadowRadius = SideMenuManager.menuShadowRadius
mainViewController.view.layer.shadowOpacity = SideMenuManager.menuShadowOpacity
mainViewController.view.layer.shadowOffset = CGSize(width: 0, height: 0)
let direction:CGFloat = SideMenuTransition.presentDirection == .left ? 1 : -1
mainViewController.view.frame.origin.x = direction * (menuView.frame.width)
mainViewController.view.layer.shadowColor = SideMenuManager.menuShadowColor.cgColor
mainViewController.view.layer.shadowRadius = SideMenuManager.menuShadowRadius
mainViewController.view.layer.shadowOpacity = SideMenuManager.menuShadowOpacity
mainViewController.view.layer.shadowOffset = CGSize(width: 0, height: 0)
case .viewSlideInOut:
menuView.alpha = 1
mainViewController.view.layer.shadowColor = SideMenuManager.menuShadowColor.cgColor
mainViewController.view.layer.shadowRadius = SideMenuManager.menuShadowRadius
mainViewController.view.layer.shadowOpacity = SideMenuManager.menuShadowOpacity
mainViewController.view.layer.shadowOffset = CGSize(width: 0, height: 0)
let direction:CGFloat = SideMenuTransition.presentDirection == .left ? 1 : -1
mainViewController.view.frame = CGRect(x: direction * (menuView.frame.width), y: 0, width: size.width, height: size.height)
mainViewController.view.transform = CGAffineTransform(scaleX: SideMenuManager.menuAnimationTransformScaleFactor, y: SideMenuManager.menuAnimationTransformScaleFactor)
mainViewController.view.alpha = 1 - SideMenuManager.menuAnimationFadeStrength
case .menuSlideIn, .menuDissolveIn:
menuView.alpha = 1
if SideMenuManager.menuBlurEffectStyle == nil {
menuView.layer.shadowColor = SideMenuManager.menuShadowColor.cgColor
menuView.layer.shadowRadius = SideMenuManager.menuShadowRadius
menuView.layer.shadowOpacity = SideMenuManager.menuShadowOpacity
menuView.layer.shadowOffset = CGSize(width: 0, height: 0)
}
mainViewController.view.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
mainViewController.view.frame.origin.x = 0
}
if SideMenuManager.menuPresentMode != .viewSlideOut {
mainViewController.view.transform = CGAffineTransform(scaleX: SideMenuManager.menuAnimationTransformScaleFactor, y: SideMenuManager.menuAnimationTransformScaleFactor)
if SideMenuManager.menuAnimationTransformScaleFactor > 1 {
SideMenuTransition.tapView?.transform = mainViewController.view.transform
}
mainViewController.view.alpha = 1 - SideMenuManager.menuAnimationFadeStrength
}
}
internal class func presentMenuComplete() {
NotificationCenter.default.addObserver(SideMenuTransition.singleton, selector:#selector(SideMenuTransition.applicationDidEnterBackgroundNotification), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
guard let mainViewController = SideMenuTransition.viewControllerForPresentedMenu else {
guard let mainViewController = presentingViewControllerForMenu else {
return
}
@@ -314,36 +365,66 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
}
}
// MARK: UIViewControllerAnimatedTransitioning protocol methods
internal func handleNotification(notification: NSNotification) {
guard let mainViewController = SideMenuTransition.presentingViewControllerForMenu,
let menuViewController = SideMenuTransition.viewControllerForMenu,
menuViewController.presentedViewController == nil && menuViewController.presentingViewController != nil else {
return
}
if let originalSuperview = SideMenuTransition.originalSuperview {
originalSuperview.addSubview(mainViewController.view)
}
if notification.name == NSNotification.Name.UIApplicationDidEnterBackground {
SideMenuTransition.hideMenuStart()
SideMenuTransition.hideMenuComplete()
menuViewController.dismiss(animated: false, completion: nil)
return
}
UIView.animate(withDuration: SideMenuManager.menuAnimationDismissDuration,
delay: 0,
usingSpringWithDamping: SideMenuManager.menuAnimationUsingSpringWithDamping,
initialSpringVelocity: SideMenuManager.menuAnimationInitialSpringVelocity,
options: SideMenuManager.menuAnimationOptions,
animations: {
SideMenuTransition.hideMenuStart()
}) { (finished) -> Void in
SideMenuTransition.hideMenuComplete()
menuViewController.dismiss(animated: false, completion: nil)
}
}
}
extension SideMenuTransition: UIViewControllerAnimatedTransitioning {
// animate a change from one viewcontroller to another
open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
// get reference to our fromView, toView and the container view that we should perform the transition in
let container = transitionContext.containerView
// prevent any other menu gestures from firing
container.isUserInteractionEnabled = false
if let menuBackgroundColor = SideMenuManager.menuAnimationBackgroundColor {
container.backgroundColor = menuBackgroundColor
}
// create a tuple of our screens
let screens : (from:UIViewController, to:UIViewController) = (transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!, transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!)
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
// assign references to our menu view controller and the 'bottom' view controller from the tuple
// remember that our menuViewController will alternate between the from and to view controller depending if we're presenting or dismissing
let menuViewController = (!presenting ? screens.from : screens.to)
let topViewController = !presenting ? screens.to : screens.from
let menuViewController = presenting ? toViewController : fromViewController
let topViewController = presenting ? fromViewController : toViewController
let menuView = menuViewController.view!
let topView = topViewController.view!
// prepare menu items to slide in
if presenting {
var tapView: UIView?
if !SideMenuManager.menuPresentingViewControllerUserInteractionEnabled {
tapView = UIView()
SideMenuTransition.tapView = tapView
}
SideMenuTransition.originalSuperview = topView.superview
// add the both views to our view controller
@@ -351,17 +432,11 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
case .viewSlideOut, .viewSlideInOut:
container.addSubview(menuView)
container.addSubview(topView)
if let tapView = tapView {
topView.addSubview(tapView)
}
case .menuSlideIn, .menuDissolveIn:
container.addSubview(topView)
if let tapView = tapView {
container.addSubview(tapView)
}
container.addSubview(menuView)
}
if SideMenuManager.menuFadeStatusBar {
let statusBarView = UIView()
SideMenuTransition.statusBarView = statusBarView
@@ -371,46 +446,32 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
SideMenuTransition.hideMenuStart()
}
let enableTapViewGestures = { (enable: Bool) in
guard let gestures = SideMenuTransition.tapView?.gestureRecognizers else {
return
}
for gesture in gestures {
gesture.isEnabled = enable
}
}
// perform the animation!
let duration = transitionDuration(using: transitionContext)
let options: UIViewAnimationOptions = interactive ? .curveLinear : UIViewAnimationOptions()
UIView.animate(withDuration: duration, delay: 0, options: options, animations: { () -> Void in
let animate = {
if self.presenting {
SideMenuTransition.presentMenuStart()
} else {
SideMenuTransition.hideMenuStart()
}
menuView.isUserInteractionEnabled = false
enableTapViewGestures(false)
}) { (finished) -> Void in
}
let complete = {
container.isUserInteractionEnabled = true
// tell our transitionContext object that we've finished animating
if transitionContext.transitionWasCancelled {
let viewControllerForPresentedMenu = SideMenuTransition.viewControllerForPresentedMenu
let viewControllerForPresentedMenu = SideMenuTransition.presentingViewControllerForMenu
if self.presenting {
SideMenuTransition.hideMenuComplete()
} else {
SideMenuTransition.presentMenuComplete()
}
menuView.isUserInteractionEnabled = true
enableTapViewGestures(true)
transitionContext.completeTransition(false)
if SideMenuTransition.switchMenus {
SideMenuTransition.switchMenus = false
viewControllerForPresentedMenu?.present(SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController! : SideMenuManager.menuRightNavigationController!, animated: true, completion: nil)
viewControllerForPresentedMenu?.present(SideMenuTransition.viewControllerForMenu!, animated: true, completion: nil)
}
return
@@ -418,8 +479,6 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
if self.presenting {
SideMenuTransition.presentMenuComplete()
menuView.isUserInteractionEnabled = true
enableTapViewGestures(true)
transitionContext.completeTransition(true)
switch SideMenuManager.menuPresentMode {
case .viewSlideOut, .viewSlideInOut:
@@ -427,6 +486,16 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
case .menuSlideIn, .menuDissolveIn:
container.insertSubview(topView, at: 0)
}
if !SideMenuManager.menuPresentingViewControllerUserInteractionEnabled {
let tapView = UIView()
container.insertSubview(tapView, aboveSubview: topView)
tapView.bounds = container.bounds
tapView.center = topView.center
if SideMenuManager.menuAnimationTransformScaleFactor > 1 {
tapView.transform = topView.transform
}
SideMenuTransition.tapView = tapView
}
if let statusBarView = SideMenuTransition.statusBarView {
container.bringSubview(toFront: statusBarView)
}
@@ -438,14 +507,43 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
transitionContext.completeTransition(true)
menuView.removeFromSuperview()
}
// perform the animation!
let duration = transitionDuration(using: transitionContext)
if interactive {
UIView.animate(withDuration: duration,
delay: 0,
options: .curveLinear,
animations: {
animate()
}, completion: { (finished) in
complete()
})
} else {
UIView.animate(withDuration: duration,
delay: 0,
usingSpringWithDamping: SideMenuManager.menuAnimationUsingSpringWithDamping,
initialSpringVelocity: SideMenuManager.menuAnimationInitialSpringVelocity,
options: SideMenuManager.menuAnimationOptions,
animations: {
animate()
}) { (finished) -> Void in
complete()
}
}
}
// return how many seconds the transiton animation will take
open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
if interactive {
return SideMenuManager.menuAnimationCompleteGestureDuration
}
return presenting ? SideMenuManager.menuAnimationPresentDuration : SideMenuManager.menuAnimationDismissDuration
}
// MARK: UIViewControllerTransitioningDelegate protocol methods
}
extension SideMenuTransition: UIViewControllerTransitioningDelegate {
// return the animator when presenting a viewcontroller
// rememeber that an animator (or animation controller) is any object that aheres to the UIViewControllerAnimatedTransitioning protocol
@@ -471,13 +569,4 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition, UIViewContr
return interactive ? SideMenuTransition.singleton : nil
}
internal func applicationDidEnterBackgroundNotification() {
if let menuViewController: UINavigationController = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController,
menuViewController.presentedViewController == nil {
SideMenuTransition.hideMenuStart()
SideMenuTransition.hideMenuComplete()
menuViewController.dismiss(animated: false, completion: nil)
}
}
}
@@ -21,7 +21,7 @@ open class UISideMenuNavigationController: UINavigationController {
}
/// Whether the menu appears on the right or left side of the screen. Right is the default.
@IBInspectable open var leftSide:Bool = false {
@IBInspectable open var leftSide: Bool = false {
didSet {
if isViewLoaded && oldValue != leftSide { // suppress warnings
didSetSide()
@@ -35,6 +35,13 @@ open class UISideMenuNavigationController: UINavigationController {
didSetSide()
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Dismiss keyboard to prevent weird keyboard animations from occurring during transition
presentingViewController?.view.endEditing(true)
}
fileprivate func didSetSide() {
if leftSide {
SideMenuManager.menuLeftNavigationController = self
@@ -46,13 +53,17 @@ open class UISideMenuNavigationController: UINavigationController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// we had presented a view before, so lets dismiss ourselves as already acted upon
// We had presented a view before, so lets dismiss ourselves as already acted upon
if view.isHidden {
SideMenuTransition.hideMenuComplete()
dismiss(animated: false, completion: { () -> Void in
self.view.isHidden = false
})
}
if topViewController == nil {
print("SideMenu Warning: the menu doesn't have a view controller to show! UISideMenuNavigationController needs a view controller to display just like a UINavigationController.")
}
}
override open func viewWillDisappear(_ animated: Bool) {
@@ -73,53 +84,60 @@ open class UISideMenuNavigationController: UINavigationController {
}
}
}
// We're presenting a view controller from the menu, so we need to hide the menu so it isn't showing when the presented view is dismissed.
UIView.animate(withDuration: SideMenuManager.menuAnimationDismissDuration,
delay: 0,
usingSpringWithDamping: SideMenuManager.menuAnimationUsingSpringWithDamping,
initialSpringVelocity: SideMenuManager.menuAnimationInitialSpringVelocity,
options: SideMenuManager.menuAnimationOptions,
animations: {
SideMenuTransition.hideMenuStart()
}) { (finished) -> Void in
self.view.isHidden = true
}
}
}
override open func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// we're presenting a view controller from the menu, so we need to hide the menu so it isn't g when the presented view is dismissed.
if !isBeingDismissed {
view.isHidden = true
SideMenuTransition.hideMenuStart()
}
// Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions
visibleViewController?.viewWillAppear(false)
}
override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
// don't bother resizing if the view isn't visible
if view.isHidden {
// Don't bother resizing if the view isn't visible
guard !view.isHidden else {
return
}
SideMenuTransition.statusBarView?.isHidden = true
coordinator.animate(alongsideTransition: { (context) -> Void in
SideMenuTransition.presentMenuStart(forSize: size)
}) { (context) -> Void in
SideMenuTransition.statusBarView?.isHidden = false
NotificationCenter.default.removeObserver(SideMenuTransition.singleton, name: NSNotification.Name.UIApplicationWillChangeStatusBarFrame, object: nil)
coordinator.animate(alongsideTransition: { (context) in
SideMenuTransition.presentMenuStart()
}) { (context) in
NotificationCenter.default.addObserver(SideMenuTransition.singleton, selector:#selector(SideMenuTransition.handleNotification), name: NSNotification.Name.UIApplicationWillChangeStatusBarFrame, object: nil)
}
}
override open func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let menuViewController: UINavigationController = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController,
let presentingViewController = menuViewController.presentingViewController as? UINavigationController {
presentingViewController.prepare(for: segue, sender: sender)
if let presentingViewController = presentingViewController {
presentingViewController.prepare(for: segue, sender: sender)
}
}
override open func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if let menuViewController: UINavigationController = SideMenuTransition.presentDirection == .left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController,
let presentingViewController = menuViewController.presentingViewController as? UINavigationController {
return presentingViewController.shouldPerformSegue(withIdentifier: identifier, sender: sender)
if let presentingViewController = presentingViewController {
return presentingViewController.shouldPerformSegue(withIdentifier: identifier, sender: sender)
}
return super.shouldPerformSegue(withIdentifier: identifier, sender: sender)
}
override open func pushViewController(_ viewController: UIViewController, animated: Bool) {
guard viewControllers.count > 0 && !SideMenuManager.menuAllowSubmenus else {
guard viewControllers.count > 0 && SideMenuManager.menuPushStyle != .subMenu else {
// NOTE: pushViewController is called by init(rootViewController: UIViewController)
// so we must perform the normal super method in this case.
super.pushViewController(viewController, animated: animated)
@@ -128,42 +146,58 @@ open class UISideMenuNavigationController: UINavigationController {
let tabBarController = presentingViewController as? UITabBarController
guard let navigationController = (tabBarController?.selectedViewController ?? presentingViewController) as? UINavigationController else {
print("SideMenu Warning: attempt to push a View Controller from \(presentingViewController.self) where its navigationController == nil. It must be embedded in a Navigation Controller for this to work.")
print("SideMenu Warning: attempt to push a View Controller from \(String(describing: presentingViewController.self)) where its navigationController == nil. It must be embedded in a Navigation Controller for this to work.")
return
}
// to avoid overlapping dismiss & pop/push calls, create a transaction block where the menu
// To avoid overlapping dismiss & pop/push calls, create a transaction block where the menu
// is dismissed after showing the appropriate screen
CATransaction.begin()
CATransaction.setCompletionBlock( { () -> Void in
self.dismiss(animated: true, completion: nil)
self.visibleViewController?.viewWillAppear(false) // Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions
})
let areAnimationsEnabled = UIView.areAnimationsEnabled
UIView.setAnimationsEnabled(true)
UIView.animate(withDuration: SideMenuManager.menuAnimationDismissDuration, animations: { () -> Void in
SideMenuTransition.hideMenuStart()
})
UIView.setAnimationsEnabled(areAnimationsEnabled)
if SideMenuManager.menuAllowPopIfPossible {
for subViewController in navigationController.viewControllers {
if let lastViewController = navigationController.viewControllers.last, !SideMenuManager.menuAllowPushOfSameClassTwice && type(of: lastViewController) == type(of: viewController) {
CATransaction.commit()
return
}
switch SideMenuManager.menuPushStyle {
case .subMenu, .defaultBehavior: break // .subMenu handled earlier, .defaultBehavior falls through to end
case .popWhenPossible:
for subViewController in navigationController.viewControllers.reversed() {
if type(of: subViewController) == type(of: viewController) {
navigationController.popToViewController(subViewController, animated: animated)
CATransaction.commit()
return
}
}
}
if SideMenuManager.menuReplaceOnPush {
case .preserve, .preserveAndHideBackButton:
var viewControllers = navigationController.viewControllers
viewControllers.removeLast()
viewControllers.append(viewController)
navigationController.setViewControllers(viewControllers, animated: animated)
CATransaction.commit()
return
}
if let lastViewController = navigationController.viewControllers.last, !SideMenuManager.menuAllowPushOfSameClassTwice && type(of: lastViewController) == type(of: viewController) {
let filtered = viewControllers.filter { preservedViewController in type(of: preservedViewController) == type(of: viewController) }
if let preservedViewController = filtered.last {
viewControllers = viewControllers.filter { subViewController in subViewController !== preservedViewController }
if SideMenuManager.menuPushStyle == .preserveAndHideBackButton {
preservedViewController.navigationItem.hidesBackButton = true
}
viewControllers.append(preservedViewController)
navigationController.setViewControllers(viewControllers, animated: animated)
CATransaction.commit()
return
}
if SideMenuManager.menuPushStyle == .preserveAndHideBackButton {
viewController.navigationItem.hidesBackButton = true
}
case .replace:
viewController.navigationItem.hidesBackButton = true
navigationController.setViewControllers([viewController], animated: animated)
CATransaction.commit()
return
}
@@ -171,6 +205,7 @@ open class UISideMenuNavigationController: UINavigationController {
navigationController.pushViewController(viewController, animated: animated)
CATransaction.commit()
}
}
+65 -32
View File
@@ -4,29 +4,34 @@
[![License](https://img.shields.io/cocoapods/l/SideMenu.svg?style=flat)](http://cocoapods.org/pods/SideMenu)
[![Platform](https://img.shields.io/cocoapods/p/SideMenu.svg?style=flat)](http://cocoapods.org/pods/SideMenu)
### If you like SideMenu, give it a ★ at the top right of its [GitHub](https://github.com/jonkykong/SideMenu) page.
### If you like SideMenu, give it a ★ at the top right of this page.
#### Using SideMenu in your app? [Send](mailto:yo@massappeal.co?subject=SideMenu%20in%20action!) me a link to your app in the app store!
My name is Jon Kent and I'm a freelance iOS designer, developer, and mobile strategist. I love coffee and play the drums. [**Hire me**](mailto:contact@jonkent.me?subject=Let's build something amazing.) to help you make cool stuff. I also have a [website](http://jonkent.me). *Note: If you're having a problem with SideMenu, please open an [issue](https://github.com/jonkykong/SideMenu/issues/new) and do not email me.*
> Hi, I'm Jon Kent and I am an iOS designer, developer, and mobile strategist. I love coffee and play the drums.
> * [**Hire me**](mailto:yo@massappeal.co?subject=Let's%20build%20something%20amazing) to help you make cool stuff. *Note: If you're having a problem with SideMenu, please open an [issue](https://github.com/jonkykong/SideMenu/issues/new) and do not email me.*
> * [Website](http://massappeal.co).
> * Building and maintaining this free library takes time. Help keep me awake and buy me a coffee ☕️ via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=contact%40jonkent%2eme&lc=US&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted).
## Overview
SideMenu is a simple and versatile side menu control written in Swift.
* **It can be implemented in storyboard without a single line of [code](#code-less-storyboard-implementation).**
* Four standard animation styles to choose from (even parallax if you want to get weird).
* Highly customizable without needing to write tons of custom code.
* Supports continuous swiping between side menus on boths sides in a single gesture.
* Global menu configuration. Set-up once and be done for all screens.
* Menus can be presented and dismissed the same as any other View Controller since this control uses custom transitions.
* **It can be implemented in storyboard without a single line of [code](#code-less-storyboard-implementation).**
* Four standard animation styles to choose from (there's even a parallax effect if you want to get weird).
* Highly customizable without needing to write tons of custom code.
* Supports continuous swiping between side menus on boths sides in a single gesture.
* Global menu configuration. Set-up once and be done for all screens.
* Menus can be presented and dismissed the same as any other view controller since this control uses [custom transitions](https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/CustomizingtheTransitionAnimations.html).
* Animations use your view controllers, not snapshots.
* Properly handles screen rotation and in-call status bar height changes.
Check out the example project to see it in action!
![](etc/SlideOut.gif)
![](etc/SlideIn.gif)
![](etc/Dissolve.gif)
![](etc/InOut.gif)
### Preview Samples
| Slide Out | Slide In | Dissolve | Slide In + Out |
| --- | --- | --- | --- |
| ![](etc/SlideOut.gif) | ![](etc/SlideIn.gif) | ![](etc/Dissolve.gif) | ![](etc/InOut.gif) |
## Requirements
* iOS 8 or higher
* iOS 8 or higher
## Installation
### CocoaPods
@@ -46,7 +51,7 @@ use_frameworks!
pod 'SideMenu'
# For Swift 2.3, use:
# For Swift 2.3 (no longer maintained), use:
# pod 'SideMenu', '~> 1.2.1'
```
@@ -75,13 +80,13 @@ github "jonkykong/SideMenu" "master"
## Usage
### Code-less Storyboard Implementation
1. Create a Navigation Controller for a side menu. Set the custom class of the Navigation Controller to be `UISideMenuNavigationController` in the **Identity Inspector**. Create a Root View Controller for the Navigation Controller (shown as a UITableViewController below). Set up any Triggered Segues you want in that View Controller.
1. Create a Navigation Controller for a side menu. Set the `Custom Class` of the Navigation Controller to be `UISideMenuNavigationController` in the **Identity Inspector**. Set the `Module` to `SideMenu` (ignore this step if you've manually added SideMenu to your project). Create a Root View Controller for the Navigation Controller (shown as a UITableViewController below). Set up any Triggered Segues you want in that view controller.
![](etc/Screenshot1.png)
2. Set the `Left Side` property of the `UISideMenuNavigationController` to On if you want it to appear from the left side of the screen, or Off/Default if you want it to appear from the right side.
![](etc/Screenshot2.png)
3. Add a UIButton or UIBarButton to a View Controller that you want to display the menu from. Set that button's Triggered Segues action to modally present the Navigation Controller from step 1.
3. Add a UIButton or UIBarButton to a view controller that you want to display the menu from. Set that button's Triggered Segues action to modally present the Navigation Controller from step 1.
![](etc/Screenshot3.png)
That's it. *Note: you can only enable gestures in code.*
@@ -91,20 +96,24 @@ First:
import SideMenu
```
In your View Controller's `viewDidLoad` event, do something like this:
In your view controller's `viewDidLoad` event, do something like this (**IMPORTANT: If you're seeing a black menu when you use gestures, read this section carefully!**):
``` swift
// Define the menus
let menuLeftNavigationController = UISideMenuNavigationController()
let menuLeftNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
menuLeftNavigationController.leftSide = true
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration of it here like setting its viewControllers.
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration
// of it here like setting its viewControllers. If you're using storyboards, you'll want to do something like:
// let menuLeftNavigationController = storyboard!.instantiateViewController(withIdentifier: "LeftMenuNavigationController") as! UISideMenuNavigationController
SideMenuManager.menuLeftNavigationController = menuLeftNavigationController
let menuRightNavigationController = UISideMenuNavigationController()
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration of it here like setting its viewControllers.
let menuRightNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
// UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration
// of it here like setting its viewControllers. If you're using storyboards, you'll want to do something like:
// let menuRightNavigationController = storyboard!.instantiateViewController(withIdentifier: "RightMenuNavigationController") as! UISideMenuNavigationController
SideMenuManager.menuRightNavigationController = menuRightNavigationController
// Enable gestures. The left and/or right menus must be set up above for these to work.
// Note that these continue to work on the Navigation Controller independent of the View Controller it displays!
// Note that these continue to work on the Navigation Controller independent of the view controller it displays!
SideMenuManager.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
```
@@ -112,13 +121,29 @@ Then from a button, do something like this:
``` swift
present(SideMenuManager.menuLeftNavigationController!, animated: true, completion: nil)
// For Swift 2.3, use:
// Similarly, to dismiss a menu programmatically, you would do this:
dismiss(animated: true, completion: nil)
// For Swift 2.3 (no longer maintained), use:
// presentViewController(SideMenuManager.menuLeftNavigationController!, animated: true, completion: nil)
```
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
/**
The push style of the menu.
There are six modes in MenuPushStyle:
- defaultBehavior: The view controller is pushed onto the stack.
- popWhenPossible: If a view controller already in the stack is of the same class as the pushed view controller, the stack is instead popped back to the existing view controller. This behavior can help users from getting lost in a deep navigation stack.
- preserve: If a view controller already in the stack is of the same class as the pushed view controller, the existing view controller is pushed to the end of the stack. This behavior is similar to a UITabBarController.
- preserveAndHideBackButton: Same as .preserve and back buttons are automatically hidden.
- replace: Any existing view controllers are released from the stack and replaced with the pushed view controller. Back buttons are automatically hidden. This behavior is ideal if view controllers require a lot of memory or their state doesn't need to be preserved..
- subMenu: Unlike all other behaviors that push using the menu's presentingViewController, this behavior pushes view controllers within the menu. Use this behavior if you want to display a sub menu.
*/
open static var menuPushStyle: MenuPushStyle = .defaultBehavior
/**
The presentation mode of the menu.
@@ -133,9 +158,6 @@ open 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.
open 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.
open 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.
open static var menuWidth: CGFloat = max(round(min((appScreenRect.width), (appScreenRect.height)) * 0.75), 240)
@@ -169,7 +191,7 @@ open static weak var menuLeftSwipeToDismissGesture: UIPanGestureRecognizer?
/// The right menu swipe to dismiss gesture.
open static weak var menuRightSwipeToDismissGesture: UIPanGestureRecognizer?
/// Enable or disable gestures that would swipe to present or dismiss the menu. Default is true.
/// Enable or disable gestures that would swipe to dismiss the menu. Default is true.
open 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.
@@ -181,11 +203,22 @@ open static var menuParallaxStrength: Int = 0
/// Draws the `menuAnimationBackgroundColor` behind the status bar. Default is true.
open static var menuFadeStatusBar = true
/// When true, pushViewController called within the menu it will push the new view controller inside of the menu. Otherwise, it is pushed on the menu's presentingViewController. Default is false.
open static var menuAllowSubmenus: Bool = false
/// The animation options when a menu is displayed. Ignored when displayed with a gesture.
open static var menuAnimationOptions: UIViewAnimationOptions = .curveEaseInOut
/// When true, pushViewController will replace the last view controller in the navigation controller's viewController stack instead of appending to it. This makes menus similar to tab bar controller behavior.
open static var menuReplaceOnPush: Bool = false
/// The animation spring damping when a menu is displayed. Ignored when displayed with a gesture.
open static var menuAnimationUsingSpringWithDamping: CGFloat = 1
/// The animation initial spring velocity when a menu is displayed. Ignored when displayed with a gesture.
open static var menuAnimationInitialSpringVelocity: CGFloat = 1
/**
Automatically dismisses the menu when another view is pushed from it.
Note: to prevent the menu from dismissing when presenting, set modalPresentationStyle = .overFullScreen
of the view controller being presented in storyboard or during its initalization.
*/
open static var menuDismissOnPush = true
/**
The blur effect style of the menu if the menu's root view controller is a UITableViewController or UICollectionViewController.
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "SideMenu"
s.version = "2.1.4"
s.version = "2.3.3"
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.
+1 -1
View File
@@ -279,7 +279,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0830;
ORGANIZATIONNAME = jonkykong;
TargetAttributes = {
7B48A0D21DCB2487002990A1 = {
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0830"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"