Compare commits

...

46 Commits

Author SHA1 Message Date
jonkykong 99ea9bb9ad Change to layer transform instead of view transform. 2018-05-23 17:03:45 -07:00
jonkykong 55776b4f9c Somewhat corrects layout problems on iOS 11. 2018-05-23 17:02:27 -07:00
jonkykong 1b6b8c446c Fix for exit gesture cancelling menu taps. 2018-02-20 02:38:33 -08:00
Jon Kent 175042e238 Update README.md 2018-01-26 11:06:54 -08:00
Jon Kent 2a4d78b7fa Update README.md 2018-01-26 11:05:26 -08:00
Jon Kent 8573045525 Update README.md 2018-01-09 02:23:18 -08:00
Jon Kent 9e5b11c1cc Update README.md 2017-12-20 10:00:40 -08:00
Jon Kent ecdbfbb11a Update README.md 2017-12-05 15:44:21 -08:00
Jon Kent 5dc207396f Update README.md 2017-11-21 14:29:57 -08:00
Jon Kent 67886c73a8 Update README.md 2017-11-21 14:29:18 -08:00
jonkykong cbc1ac6624 Update README for Github. 2017-11-21 13:20:38 -08:00
jonkykong 9c7111e7e3 Merge tag '3.1.5'
* tag '3.1.5':
  Updated README requirements.
  Updated README for Cocoapods.
  Exposed defaultManager for Objective-C support.
  Updated podspec.
  Additional changes for objective-C support in UISideMenuNavigationController
  fix objc inference in swift 4
2017-11-21 13:19:21 -08:00
jonkykong df48679df4 Updated README requirements. 2017-11-21 13:15:29 -08:00
jonkykong f32cf72443 Updated README for Cocoapods. 2017-11-21 13:10:30 -08:00
jonkykong b15180fb8a Exposed defaultManager for Objective-C support. 2017-11-21 13:06:57 -08:00
jonkykong 6eae7987ef Updated podspec. 2017-11-21 13:05:03 -08:00
jonkykong c6b7780daf Additional changes for objective-C support in UISideMenuNavigationController 2017-11-21 13:04:52 -08:00
herrernst c54f364d49 fix objc inference in swift 4
in swift 4, swift subclasses of objective-c classes don't export members by default, see https://help.apple.com/xcode/mac/current/#/deve838b19a1
2017-11-07 12:27:45 +01:00
jonkykong 5ac61bc981 Revert README for Cocoapods. 2017-10-31 00:31:17 -07:00
jonkykong b647880794 Merge tag '3.1.4'
* tag '3.1.4':
  Update README for Cocoapods.
  Updated podspec.
  Fixed SideMenu.UISideMenuNavigationController crash on init(nibName:bundle:)
2017-10-31 00:30:51 -07:00
jonkykong 2e684440fc Update README for Cocoapods. 2017-10-31 00:28:19 -07:00
jonkykong 6064d6d5fc Updated podspec. 2017-10-31 00:27:58 -07:00
Lawrence Gimenez d13ed0ea9b Fixed SideMenu.UISideMenuNavigationController crash on init(nibName:bundle:) 2017-10-31 15:06:59 +08:00
jonkykong ef607b3ab2 Update README for Github. 2017-10-28 12:05:27 -07:00
jonkykong 069b974145 Merge tag '3.1.3'
* tag '3.1.3':
  Update README for cocoapods.
  Updated podspec.
  Updated README.
2017-10-28 12:04:53 -07:00
jonkykong 3e452b2a69 Update README for cocoapods. 2017-10-28 11:58:48 -07:00
jonkykong 021fe8cd6a Merge branch 'master' into 3.1.3
* master:
  Exposed delegate to @objc.
  Adding omitted initializer.
  README corrections.
2017-10-28 11:58:01 -07:00
jonkykong fd6ecbbece Updated podspec. 2017-10-28 11:55:43 -07:00
jonkykong 313cda5d69 Updated README. 2017-10-28 11:55:24 -07:00
jonkykong e35a46b075 Exposed delegate to @objc. 2017-10-28 11:52:58 -07:00
jonkykong 3702ecb770 Adding omitted initializer. 2017-10-28 11:52:23 -07:00
jonkykong 893818b582 README corrections. 2017-10-26 18:48:29 -07:00
jonkykong f21ed8965d Revert README for Github. 2017-10-26 18:40:22 -07:00
jonkykong db1cf2a6b6 Merge tag '3.1.2'
* tag '3.1.2':
  Updated podspec.
  Updated README.
  Allow for specifying the sideMenuDelegate, otherwise it discovers it automatically.
  Last commit was incorrect -- but this commit fixes it and includes a work-around for more experience devs who may still want to use default initializer as well as silence some newbie warnings.
  Override of navigation controller default init to prevent new developers from seeing black menus.
  It should be possible now to have the menu slide out even if pushing the new view is not animated itself (animating both can look a bit weird when relying on 'animated' only)
2017-10-26 18:39:49 -07:00
jonkykong a66367d84a Updated podspec. 2017-10-26 18:10:58 -07:00
jonkykong 5f8bdab1dc Updated README. 2017-10-26 18:10:23 -07:00
jonkykong 86f592a20d Support for forcing animated menu dismissal even when pushed view controllers are not animated. 2017-10-26 18:08:43 -07:00
jonkykong dd0a14fa61 Allow for specifying the sideMenuDelegate, otherwise it discovers it automatically. 2017-10-26 17:07:46 -07:00
jonkykong 2ba0ef7453 Last commit was incorrect -- but this commit fixes it and includes a work-around for more experience devs who may still want to use default initializer as well as silence some newbie warnings. 2017-10-24 12:15:41 -07:00
jonkykong 6f57e37129 Override of navigation controller default init to prevent new developers from seeing black menus. 2017-10-24 12:13:06 -07:00
Andreas Hilbert 2af0d86c97 It should be possible now to have the menu slide out even if pushing the new view is not animated itself (animating both can look a bit weird when relying on 'animated' only) 2017-10-19 12:11:20 +02:00
Jon Kent 3dc08de6ec Update README.md 2017-10-17 20:03:10 -07:00
Jon Kent 646f2a8094 Update README.md 2017-10-16 23:18:59 -07:00
Jon Kent ef867ff2b3 Update README.md 2017-10-16 23:18:26 -07:00
jonkykong 49dd185fa7 Updated README for Github. 2017-10-11 14:45:34 -07:00
jonkykong 6a87536f76 Merge tag '3.1.1'
* tag '3.1.1':
  Updated podspec.
  Update README for Cocoapods.
  README correction.
  Better logic for managing UISideMenuNavigationController properties across interface builder and programmatic instantiations.
2017-10-11 14:45:10 -07:00
5 changed files with 183 additions and 79 deletions
+19
View File
@@ -16,6 +16,7 @@
SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
*/
@objcMembers
open class SideMenuManager : NSObject {
@objc public enum MenuPushStyle : Int {
@@ -127,8 +128,19 @@ open class SideMenuManager : NSObject {
*/
open var menuDismissOnPush = true
/// Forces menus to always animate when appearing or disappearing, regardless of a pushed view controller's animation.
open var menuAlwaysAnimate = false
/// Default instance of SideMenuManager.
open static let `default` = SideMenuManager()
/// Default instance of SideMenuManager (objective-C).
open class var defaultManager: SideMenuManager {
get {
return SideMenuManager.default
}
}
internal var transition: SideMenuTransition!
public override init() {
@@ -227,11 +239,13 @@ open class SideMenuManager : NSObject {
forMenu.leftSide = leftSide
if forMenu.sideMenuManager != self {
#if !STFU_SIDEMENU
if forMenu.sideMenuManager?.menuLeftNavigationController == forMenu {
print("SideMenu Warning: \(String(describing: forMenu.self)) was already assigned to the menuLeftNavigationController of \(String(describing: forMenu.sideMenuManager!.self)). When using multiple SideMenuManagers you may want to use new instances of UISideMenuNavigationController instead of existing instances to avoid crashes if the menu is presented more than once.")
} else if forMenu.sideMenuManager?.menuRightNavigationController == forMenu {
print("SideMenu Warning: \(String(describing: forMenu.self)) was already assigned to the menuRightNavigationController of \(String(describing: forMenu.sideMenuManager!.self)). When using multiple SideMenuManagers you may want to use new instances of UISideMenuNavigationController instead of existing instances to avoid crashes if the menu is presented more than once.")
}
#endif
forMenu.sideMenuManager = self
}
@@ -239,6 +253,7 @@ open class SideMenuManager : NSObject {
if menuEnableSwipeGestures {
let exitPanGesture = UIPanGestureRecognizer()
exitPanGesture.cancelsTouchesInView = false
forMenu.view.addGestureRecognizer(exitPanGesture)
if leftSide {
menuLeftSwipeToDismissGesture = exitPanGesture
@@ -343,9 +358,11 @@ open class SideMenuManager : NSObject {
leftScreenEdgeGestureRecognizer.addTarget(transition, action:#selector(SideMenuTransition.handlePresentMenuLeftScreenEdge(_:)))
leftScreenEdgeGestureRecognizer.edges = .left
#if !STFU_SIDEMENU
if menuLeftNavigationController == nil {
print("SideMenu Warning: menuAddScreenEdgePanGesturesToPresent was called before menuLeftNavigationController was set. The gesture will not work without a menu. Use menuAddScreenEdgePanGesturesToPresent(toView:forMenu:) to add gestures for only one menu.")
}
#endif
}
if forMenu != .left {
@@ -353,9 +370,11 @@ open class SideMenuManager : NSObject {
rightScreenEdgeGestureRecognizer.addTarget(transition, action:#selector(SideMenuTransition.handlePresentMenuRightScreenEdge(_:)))
rightScreenEdgeGestureRecognizer.edges = .right
#if !STFU_SIDEMENU
if menuRightNavigationController == nil {
print("SideMenu Warning: menuAddScreenEdgePanGesturesToPresent was called before menuRightNavigationController was set. The gesture will not work without a menu. Use menuAddScreenEdgePanGesturesToPresent(toView:forMenu:) to add gestures for only one menu.")
}
#endif
}
return array
+55 -19
View File
@@ -125,10 +125,10 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
return
}
let transform = view.transform
view.transform = .identity
let transform = view.layer.transform
view.layer.transform = CATransform3DIdentity
let translation = pan.translation(in: pan.view!)
view.transform = transform
view.layer.transform = transform
// do some math to translate this to a percentage based value
if !interactive {
@@ -166,9 +166,9 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
}
default:
interactive = false
view.transform = .identity
view.layer.transform = CATransform3DIdentity
let velocity = pan.velocity(in: pan.view!).x * direction
view.transform = transform
view.layer.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 && percentComplete > 1 - CGFloat.ulpOfOne {
@@ -226,10 +226,10 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
let menuView = menuViewController?.view
let mainView = mainViewController?.view
mainView?.transform = .identity
mainView?.layer.transform = CATransform3DIdentity
mainView?.alpha = 1
mainView?.frame.origin = .zero
menuView?.transform = .identity
menuView?.layer.transform = CATransform3DIdentity
menuView?.frame.origin.y = 0
menuView?.frame.size.width = menuWidth
menuView?.frame.size.height = mainView?.frame.height ?? 0 // in case status bar height changed
@@ -248,7 +248,11 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
case .viewSlideOut:
menuView?.alpha = 1 - sideMenuManager.menuAnimationFadeStrength
menuView?.frame.origin.x = presentDirection == .left ? 0 : (mainView?.frame.width ?? 0) - menuWidth
menuView?.transform = CGAffineTransform(scaleX: sideMenuManager.menuAnimationTransformScaleFactor, y: sideMenuManager.menuAnimationTransformScaleFactor)
let f = sideMenuManager.menuAnimationTransformScaleFactor
menuView?.layer.transform = CATransform3D(m11: f, m12: 0, m13: 0, m14: 0,
m21: 0, m22: f, m23: 0, m24: 0,
m31: 0, m32: 0, m33: 1, m34: 0,
m41: 0, m42: 0, m43: 0, m44: 1)
case .viewSlideInOut:
menuView?.alpha = 1
@@ -295,11 +299,11 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
let mainView = mainViewController?.view
menuView?.alpha = 1
menuView?.transform = .identity
menuView?.layer.transform = CATransform3DIdentity
menuView?.frame.size.width = menuWidth
let size = SideMenuManager.appScreenRect.size
menuView?.frame.origin.x = presentDirection == .left ? 0 : size.width - menuWidth
mainView?.transform = .identity
mainView?.layer.transform = CATransform3DIdentity
mainView?.frame.size.width = size.width
let statusBarOffset = size.height - (menuView?.bounds.height ?? 0)
mainView?.bounds.size.height = size.height - max(statusBarOffset, 0)
@@ -310,11 +314,12 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
if statusBarOffset >= CGFloat.ulpOfOne {
statusBarFrame.size.height = statusBarOffset
}
tapView?.transform = .identity
tapView?.layer.transform = CATransform3DIdentity
tapView?.bounds = mainView!.bounds
statusBarView?.frame = statusBarFrame
statusBarView?.alpha = 1
var x: CGFloat = 0
switch sideMenuManager.menuPresentMode {
case .viewSlideOut, .viewSlideInOut:
@@ -323,7 +328,7 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
mainView?.layer.shadowOpacity = sideMenuManager.menuShadowOpacity
mainView?.layer.shadowOffset = CGSize(width: 0, height: 0)
let direction:CGFloat = presentDirection == .left ? 1 : -1
mainView?.frame.origin.x = direction * (menuView!.frame.width)
x = direction * (menuView!.frame.width)
case .menuSlideIn, .menuDissolveIn:
if sideMenuManager.menuBlurEffectStyle == nil {
@@ -332,17 +337,21 @@ open class SideMenuTransition: UIPercentDrivenInteractiveTransition {
menuView?.layer.shadowOpacity = sideMenuManager.menuShadowOpacity
menuView?.layer.shadowOffset = CGSize(width: 0, height: 0)
}
mainView?.frame.origin.x = 0
}
if sideMenuManager.menuPresentMode != .viewSlideOut {
mainView?.transform = CGAffineTransform(scaleX: sideMenuManager.menuAnimationTransformScaleFactor, y: sideMenuManager.menuAnimationTransformScaleFactor)
if sideMenuManager.menuAnimationTransformScaleFactor > 1 {
tapView?.transform = mainView!.transform
}
let f = sideMenuManager.menuPresentMode != .viewSlideOut ? sideMenuManager.menuAnimationTransformScaleFactor : 1
if sideMenuManager.menuPresentMode == .viewSlideInOut || sideMenuManager.menuPresentMode == .viewSlideOut {
mainView?.alpha = 1 - sideMenuManager.menuAnimationFadeStrength
}
mainView?.layer.transform = CATransform3D(m11: f, m12: 0, m13: 0, m14: 0,
m21: 0, m22: f, m23: 0, m24: 0,
m31: 0, m32: 0, m33: 1, m34: 0,
m41: x, m42: 0, m43: 0, m44: 1)
if f > 1 {
tapView?.layer.transform = mainView!.layer.transform
}
return self
}
@@ -447,6 +456,18 @@ extension SideMenuTransition: UIViewControllerAnimatedTransitioning {
}
hideMenuStart()
if #available(iOS 11.0, *), sideMenuManager.menuAnimationTransformScaleFactor != 1.0 {
mainViewController?.additionalSafeAreaInsets.top = topView.safeAreaLayoutGuide.layoutFrame.minY
if sideMenuManager.menuAnimationTransformScaleFactor < 1.0 {
mainViewController?.additionalSafeAreaInsets.bottom = topView.frame.maxY - topView.safeAreaLayoutGuide.layoutFrame.maxY
}
}
} else {
if #available(iOS 11.0, *), sideMenuManager.menuAnimationTransformScaleFactor != 1.0 {
mainViewController?.additionalSafeAreaInsets.top = 0
mainViewController?.additionalSafeAreaInsets.bottom = 0
}
}
let animate = {
@@ -465,8 +486,23 @@ extension SideMenuTransition: UIViewControllerAnimatedTransitioning {
let viewControllerForPresentedMenu = self.mainViewController
if self.presenting {
if #available(iOS 11.0, *), self.sideMenuManager.menuAnimationTransformScaleFactor != 1.0 {
self.mainViewController?.additionalSafeAreaInsets.top = 0
self.mainViewController?.additionalSafeAreaInsets.bottom = 0
}
self.hideMenuComplete()
} else {
if #available(iOS 11.0, *), self.sideMenuManager.menuAnimationTransformScaleFactor != 1.0 {
let transform = topView.layer.transform
topView.layer.transform = CATransform3DIdentity
self.mainViewController?.additionalSafeAreaInsets.top = topView.safeAreaLayoutGuide.layoutFrame.minY
if self.sideMenuManager.menuAnimationTransformScaleFactor < 1.0 {
self.mainViewController?.additionalSafeAreaInsets.bottom = topView.frame.maxY - topView.safeAreaLayoutGuide.layoutFrame.maxY
}
topView.layer.transform = transform
}
self.presentMenuComplete()
}
@@ -495,7 +531,7 @@ extension SideMenuTransition: UIViewControllerAnimatedTransitioning {
tapView.bounds = container.bounds
tapView.center = topView.center
if self.sideMenuManager.menuAnimationTransformScaleFactor > 1 {
tapView.transform = topView.transform
tapView.layer.transform = topView.layer.transform
}
self.tapView = tapView
}
@@ -7,24 +7,26 @@
import UIKit
public protocol UISideMenuNavigationControllerDelegate: class {
func sideMenuWillAppear(menu: UISideMenuNavigationController, animated: Bool)
func sideMenuDidAppear(menu: UISideMenuNavigationController, animated: Bool)
func sideMenuWillDisappear(menu: UISideMenuNavigationController, animated: Bool)
func sideMenuDidDisappear(menu: UISideMenuNavigationController, animated: Bool)
}
// This makes adherance to the protocol optional:
extension UIViewController {
func sideMenuWillAppear(menu: UISideMenuNavigationController, animated: Bool) {}
func sideMenuDidAppear(menu: UISideMenuNavigationController, animated: Bool) {}
func sideMenuWillDisappear(menu: UISideMenuNavigationController, animated: Bool) {}
func sideMenuDidDisappear(menu: UISideMenuNavigationController, animated: Bool) {}
@objc public protocol UISideMenuNavigationControllerDelegate {
@objc optional func sideMenuWillAppear(menu: UISideMenuNavigationController, animated: Bool)
@objc optional func sideMenuDidAppear(menu: UISideMenuNavigationController, animated: Bool)
@objc optional func sideMenuWillDisappear(menu: UISideMenuNavigationController, animated: Bool)
@objc optional func sideMenuDidDisappear(menu: UISideMenuNavigationController, animated: Bool)
}
@objcMembers
open class UISideMenuNavigationController: UINavigationController {
fileprivate weak var temporarySideMenuDelegate: UISideMenuNavigationControllerDelegate?
fileprivate weak var foundDelegate: UISideMenuNavigationControllerDelegate?
fileprivate weak var activeDelegate: UISideMenuNavigationControllerDelegate? {
get {
guard !view.isHidden else {
return nil
}
return sideMenuDelegate ?? foundDelegate ?? findDelegate(forViewController: presentingViewController)
}
}
fileprivate func findDelegate(forViewController: UIViewController?) -> UISideMenuNavigationControllerDelegate? {
if let navigationController = forViewController as? UINavigationController {
return findDelegate(forViewController: navigationController.topViewController)
@@ -36,8 +38,8 @@ open class UISideMenuNavigationController: UINavigationController {
return findDelegate(forViewController: splitViewController.viewControllers.last)
}
temporarySideMenuDelegate = forViewController as? UISideMenuNavigationControllerDelegate
return temporarySideMenuDelegate
foundDelegate = forViewController as? UISideMenuNavigationControllerDelegate
return foundDelegate
}
fileprivate var usingInterfaceBuilder = false
internal var locked = false
@@ -47,15 +49,9 @@ open class UISideMenuNavigationController: UINavigationController {
return sideMenuManager.transition
}
}
internal var sideMenuDelegate: UISideMenuNavigationControllerDelegate? {
get {
guard !view.isHidden else {
return nil
}
return temporarySideMenuDelegate ?? findDelegate(forViewController: presentingViewController)
}
}
/// Delegate for receiving appear and disappear related events. If `nil` the visible view controller that displays a `UISideMenuNavigationController` automatically receives these events.
open weak var sideMenuDelegate: UISideMenuNavigationControllerDelegate?
/// SideMenuManager instance associated with this menu. Default is `SideMenuManager.default`. This property cannot be changed after the menu has loaded.
open weak var sideMenuManager: SideMenuManager! = SideMenuManager.default {
@@ -94,6 +90,28 @@ open class UISideMenuNavigationController: UINavigationController {
}
}
#if !STFU_SIDEMENU
// This override prevents newbie developers from creating black/blank menus and opening newbie issues.
// If you would like to remove this override, define STFU_SIDEMENU in the Active Compilation Conditions of your .plist file.
// Sorry for the inconvenience experienced developers :(
@available(*, unavailable, renamed: "init(rootViewController:)")
public init() {
fatalError("init is not available")
}
public override init(rootViewController: UIViewController) {
super.init(rootViewController: rootViewController)
}
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
#endif
open override func awakeFromNib() {
super.awakeFromNib()
@@ -118,8 +136,8 @@ open class UISideMenuNavigationController: UINavigationController {
// Dismiss keyboard to prevent weird keyboard animations from occurring during transition
presentingViewController?.view.endEditing(true)
temporarySideMenuDelegate = nil
sideMenuDelegate?.sideMenuWillAppear(menu: self, animated: animated)
foundDelegate = nil
activeDelegate?.sideMenuWillAppear?(menu: self, animated: animated)
}
override open func viewDidAppear(_ animated: Bool) {
@@ -135,11 +153,13 @@ open class UISideMenuNavigationController: UINavigationController {
return
}
sideMenuDelegate?.sideMenuDidAppear(menu: self, animated: animated)
activeDelegate?.sideMenuDidAppear?(menu: self, animated: animated)
#if !STFU_SIDEMENU
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.")
}
#endif
}
override open func viewWillDisappear(_ animated: Bool) {
@@ -173,16 +193,16 @@ open class UISideMenuNavigationController: UINavigationController {
options: sideMenuManager.menuAnimationOptions,
animations: {
self.transition.hideMenuStart()
self.sideMenuDelegate?.sideMenuWillDisappear(menu: self, animated: animated)
self.activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}) { (finished) -> Void in
self.sideMenuDelegate?.sideMenuDidDisappear(menu: self, animated: animated)
self.activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
self.view.isHidden = true
}
return
}
sideMenuDelegate?.sideMenuWillDisappear(menu: self, animated: animated)
activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
}
override open func viewDidDisappear(_ animated: Bool) {
@@ -192,11 +212,11 @@ open class UISideMenuNavigationController: UINavigationController {
// the view hierarchy leaving the screen black/empty. This is because the transition moves views within a container
// view, but dismissing without animation removes the container view before the original hierarchy is restored.
// This check corrects that.
if let sideMenuDelegate = sideMenuDelegate as? UIViewController, sideMenuDelegate.view.window == nil {
if let sideMenuDelegate = activeDelegate as? UIViewController, sideMenuDelegate.view.window == nil {
transition.hideMenuStart().hideMenuComplete()
}
sideMenuDelegate?.sideMenuDidDisappear(menu: self, animated: animated)
activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
// Clear selecton on UITableViewControllers when reappearing using custom transitions
guard let tableViewController = topViewController as? UITableViewController,
@@ -243,15 +263,17 @@ open class UISideMenuNavigationController: UINavigationController {
return
}
let sideMenuDelegate = self.sideMenuDelegate
temporarySideMenuDelegate = nil
let activeDelegate = self.activeDelegate
foundDelegate = nil
// To avoid overlapping dismiss & pop/push calls, create a transaction block where the menu
// is dismissed after showing the appropriate screen
CATransaction.begin()
if sideMenuManager.menuDismissOnPush {
let animated = animated || sideMenuManager.menuAlwaysAnimate
CATransaction.setCompletionBlock( { () -> Void in
sideMenuDelegate?.sideMenuDidDisappear(menu: self, animated: animated)
activeDelegate?.sideMenuDidDisappear?(menu: self, animated: animated)
if !animated {
self.transition.hideMenuStart().hideMenuComplete()
}
@@ -267,7 +289,7 @@ open class UISideMenuNavigationController: UINavigationController {
initialSpringVelocity: sideMenuManager.menuAnimationInitialSpringVelocity,
options: sideMenuManager.menuAnimationOptions,
animations: {
sideMenuDelegate?.sideMenuWillDisappear(menu: self, animated: animated)
activeDelegate?.sideMenuWillDisappear?(menu: self, animated: animated)
self.transition.hideMenuStart()
})
UIView.setAnimationsEnabled(areAnimationsEnabled)
+49 -22
View File
@@ -1,37 +1,59 @@
# ▤ SideMenu
[![Version](https://img.shields.io/cocoapods/v/SideMenu.svg?style=flat)](http://cocoapods.org/pods/SideMenu)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![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)
[![Version](https://img.shields.io/cocoapods/v/SideMenu.svg?style=flat-square)](http://cocoapods.org/pods/SideMenu)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square)](https://github.com/Carthage/Carthage)
[![License](https://img.shields.io/cocoapods/l/SideMenu.svg?style=flat-square)](http://cocoapods.org/pods/SideMenu)
[![Platform](https://img.shields.io/cocoapods/p/SideMenu.svg?style=flat-square)](http://cocoapods.org/pods/SideMenu)
[![Total Downloads](https://img.shields.io/cocoapods/dt/SideMenu.svg?style=social)](http://cocoapods.org/pods/SideMenu)
[![Monthly Downloads](https://img.shields.io/cocoapods/dm/SideMenu.svg?style=social)](http://cocoapods.org/pods/SideMenu)
[![Weekly Downloads](https://img.shields.io/cocoapods/dw/SideMenu.svg?style=social)](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!
> 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.*
> * Check out my [website](http://massappeal.co) to see some of my other projects.
> * 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).
> * Building and maintaining this **free** library takes a lot of my time and **saves you time**. Please consider paying it forward by supporting me with a small amount to my [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). (only **2** people have donated since inception 😕 but **thank you** to those who have!)
* **[Overview](#overview)**
* [Preview Samples](#preview-samples)
* **[Requirements](#requirements)**
* **[Installation](#installation)**
* [CocoaPods](#cocoapods)
* [Carthage](#carthage)
* **[Usage](#usage)**
* [Code-less Storyboard Implementation](#code-less-storyboard-implementation)
* [Code Implementation](#code-implementation)
* **[Customization](#customization)**
* [SideMenuManager](#sidemenumanager)
* [UISideMenuNavigationController](#uisidemenunavigationcontroller)
* [UISideMenuNavigationControllerDelegate](#uisidemenunavigationcontrollerdelegate)
* [Advanced](#advanced)
* [Known Issues](#known-issues)
* [Thank You](#thank-you)
* [License](#license)
## Overview
SideMenu is a simple and versatile side menu control written in Swift.
- [x] **It can be implemented in storyboard without a single line of [code](#code-less-storyboard-implementation).**
- [x] Four standard animation styles to choose from (there's even a parallax effect if you want to get weird).
- [x] Highly customizable without needing to write tons of custom code.
- [x] Supports continuous swiping between side menus on boths sides in a single gesture.
- [x] Global menu configuration. Set-up once and be done for all screens.
- [x] 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).
- [x] Animations use your view controllers, not snapshots.
- [x] Properly handles screen rotation and in-call status bar height changes.
* **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!
### Preview Samples
| Slide Out | Slide In | Dissolve | Slide In + Out |
| --- | --- | --- | --- |
| ![](etc/SlideOut.gif) | ![](etc/SlideIn.gif) | ![](etc/Dissolve.gif) | ![](etc/InOut.gif) |
| ![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/SlideOut.gif) | ![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/SlideIn.gif) | ![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/Dissolve.gif) | ![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/InOut.gif) |
## Requirements
- [x] iOS 8 or higher.
* Xcode 9.
* iOS 8 or higher.
## Installation
### CocoaPods
@@ -81,13 +103,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**. 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)
![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/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)
![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/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.
![](etc/Screenshot3.png)
![](https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/Screenshot3.png)
That's it. *Note: you can only enable gestures in code.*
### Code Implementation
@@ -126,7 +148,7 @@ dismiss(animated: true, completion: nil)
That's it.
### Customization
#### SideMenuManager
Just type ` SideMenuManager.default.menu...` and code completion will show you everything you can customize (defaults are shown below for reference):
Just type ` SideMenuManager.default.menu...` and code completion will show you everything you can customize (for Objective-C, use `SideMenuManager.defaultManager.menu...`). Defaults values are shown below for reference:
``` swift
/**
The push style of the menu.
@@ -136,7 +158,7 @@ There are six modes in MenuPushStyle:
- 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..
- 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 var menuPushStyle: MenuPushStyle = .defaultBehavior
@@ -224,6 +246,9 @@ of the view controller being presented in storyboard or during its initalization
*/
open var menuDismissOnPush = true
/// Forces menus to always animate when appearing or disappearing, regardless of a pushed view controller's animation.
open var menuAlwaysAnimate = false
/**
The blur effect style of the menu if the menu's root view controller is a UITableViewController or UICollectionViewController.
@@ -294,6 +319,7 @@ extension MyViewController: UISideMenuNavigationControllerDelegate {
}
```
*Note: setting the `sideMenuDelegate` property on `UISideMenuNavigationController` is optional. If your view controller adheres to the protocol then the methods will be called automatically.*
### Advanced
For simplicity, `SideMenuManager.default` serves as the primary instance as most projects will only need one menu across all screens. If you need to show a different SideMenu, such as from a modal view controller presented from a previous SideMenu, do the following:
1. Declare a variable containing your custom `SideMenuManager` instance. You may want it to define it globally and configure it in your app delegate if menus will be used on multiple screens.
@@ -325,7 +351,8 @@ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
```
*Important: displaying SideMenu instances directly over each other is not supported. Use `menuPushStyle = .subMenu` instead.*
## Known Issues
Don't try to change the status bar appearance when presenting a menu. When used with quick gestures/animations, it causes the presentation animation to not complete properly and locks the UI. This was fixed in iOS 9.3. See [radar 21961293](http://www.openradar.me/21961293) for more information.
* Issue [#258](https://github.com/jonkykong/SideMenu/issues/258).
* Don't try to change the status bar appearance when presenting a menu. When used with quick gestures/animations, it causes the presentation animation to not complete properly and locks the UI. This was fixed in iOS 9.3. See [radar 21961293](http://www.openradar.me/21961293) for more information.
## Thank You
A special thank you to everyone that has [contributed](https://github.com/jonkykong/SideMenu/graphs/contributors) to this library to make it better. Your support is appreciated!
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = "SideMenu"
s.version = "3.1.1"
s.version = "3.1.5"
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.