Compare commits

...

12 Commits

Author SHA1 Message Date
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
4 changed files with 59 additions and 26 deletions
+9
View File
@@ -127,6 +127,9 @@ 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()
internal var transition: SideMenuTransition!
@@ -227,11 +230,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
}
@@ -343,9 +348,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 +360,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
@@ -24,7 +24,16 @@ extension UIViewController {
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 +45,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 +56,7 @@ open class UISideMenuNavigationController: UINavigationController {
return sideMenuManager.transition
}
}
internal var sideMenuDelegate: UISideMenuNavigationControllerDelegate? {
get {
guard !view.isHidden else {
return nil
}
return temporarySideMenuDelegate ?? findDelegate(forViewController: presentingViewController)
}
}
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 +95,20 @@ 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 required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
#endif
open override func awakeFromNib() {
super.awakeFromNib()
@@ -118,8 +133,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 +150,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 +190,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 +209,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 +260,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 +286,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)
+6 -1
View File
@@ -224,6 +224,9 @@ of the view controller being presented in storyboard or during its initalization
*/
open var menuDismissOnPush = true
/// Uses the menu dismiss animation even if pushing a view is not animated itself.
open var menuAnimateDismissOnNonAnimatedPush = false
/**
The blur effect style of the menu if the menu's root view controller is a UITableViewController or UICollectionViewController.
@@ -294,6 +297,7 @@ extension MyViewController: UISideMenuNavigationControllerDelegate {
}
```
*Note: there is no `delegate` property to set on the `UISideMenuNavigationController` for this to work. 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 +329,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.2"
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.