diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 950ec16..fc78fa3 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - SideMenu (0.1.0) + - SideMenu (0.1.1) DEPENDENCIES: - SideMenu (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - SideMenu: 62c97561370244e645f3bccecb8a9055f78d0ccc + SideMenu: f523126587f807b71b4308a64a7f33e9c096833a COCOAPODS: 0.39.0 diff --git a/Example/Pods/Local Podspecs/SideMenu.podspec.json b/Example/Pods/Local Podspecs/SideMenu.podspec.json index b4de1b0..fce98a6 100644 --- a/Example/Pods/Local Podspecs/SideMenu.podspec.json +++ b/Example/Pods/Local Podspecs/SideMenu.podspec.json @@ -1,16 +1,17 @@ { "name": "SideMenu", - "version": "0.1.0", + "version": "0.1.1", "summary": "SideMenu is a simple and versatile side menu control.", - "description": "SideMenu is a simple and versatile side menu control. It's highly customizable, but can also be implemented in storyboard without a single line of code. The are three standard animation styles to choose from along with several other options for further customization if desired.", + "description": "SideMenu is a simple and versatile side menu control. It's highly customizable, but can also be implemented in storyboard without a single line of code. The are three standard animation styles to choose from along with several other options for further customization if desired. Just type SideMenuManager.menu... and code completion will show you everything you can customize.", "homepage": "https://github.com/jonkykong/SideMenu", + "screenshots": "https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/Preview.gif", "license": "MIT", "authors": { "jonkykong": "jonk@jonked.com" }, "source": { "git": "https://github.com/jonkykong/SideMenu.git", - "tag": "0.1.0" + "tag": "0.1.1" }, "platforms": { "ios": "8.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index 950ec16..fc78fa3 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -1,5 +1,5 @@ PODS: - - SideMenu (0.1.0) + - SideMenu (0.1.1) DEPENDENCIES: - SideMenu (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - SideMenu: 62c97561370244e645f3bccecb8a9055f78d0ccc + SideMenu: f523126587f807b71b4308a64a7f33e9c096833a COCOAPODS: 0.39.0 diff --git a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/SideMenu.xcscheme b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/SideMenu.xcscheme index f3622cb..c09da8d 100644 --- a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/SideMenu.xcscheme +++ b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/SideMenu.xcscheme @@ -14,7 +14,7 @@ buildForArchiving = "YES"> diff --git a/Example/Pods/Target Support Files/SideMenu/Info.plist b/Example/Pods/Target Support Files/SideMenu/Info.plist index 4ba5fa2..c3f6ee3 100644 --- a/Example/Pods/Target Support Files/SideMenu/Info.plist +++ b/Example/Pods/Target Support Files/SideMenu/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.0 + 0.1.1 CFBundleSignature ???? CFBundleVersion diff --git a/Example/SideMenu/Main.storyboard b/Example/SideMenu/Main.storyboard index 2ced5ea..3cef256 100644 --- a/Example/SideMenu/Main.storyboard +++ b/Example/SideMenu/Main.storyboard @@ -1,6 +1,7 @@ + @@ -92,7 +93,7 @@ - + @@ -242,15 +243,18 @@ - + - + + + + @@ -375,10 +379,10 @@ - + - + diff --git a/Example/SideMenu/MainViewController.swift b/Example/SideMenu/MainViewController.swift index 2750e47..bf32c93 100644 --- a/Example/SideMenu/MainViewController.swift +++ b/Example/SideMenu/MainViewController.swift @@ -26,8 +26,8 @@ class MainViewController: UIViewController { private func setupSideMenu() { // Define the menus - SideMenuManager.menuLeftNavigationController = storyboard!.instantiateViewControllerWithIdentifier("UILeftMenuNavigationController") as? UILeftMenuNavigationController - SideMenuManager.menuRightNavigationController = storyboard!.instantiateViewControllerWithIdentifier("UIRightMenuNavigationController") as? UIRightMenuNavigationController + SideMenuManager.menuLeftNavigationController = storyboard!.instantiateViewControllerWithIdentifier("LeftMenuNavigationController") as? UIMenuNavigationController + SideMenuManager.menuRightNavigationController = storyboard!.instantiateViewControllerWithIdentifier("RightMenuNavigationController") as? UIMenuNavigationController // 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! diff --git a/Pod/Classes/SideMenuManager.swift b/Pod/Classes/SideMenuManager.swift index 57c486b..3757733 100644 --- a/Pod/Classes/SideMenuManager.swift +++ b/Pod/Classes/SideMenuManager.swift @@ -12,168 +12,143 @@ SideMenuManager.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view) */ -private func menuViewDidAppear(navigationController: UINavigationController) { - // we had presented a view before, so lets dismiss ourselves as already acted upon - if navigationController.view.hidden { - SideMenuManager.hideMenuComplete() - navigationController.dismissViewControllerAnimated(false, completion: { () -> Void in - navigationController.view.hidden = false - }) - } -} - -private func menuViewWillDisappear(navigationController: UINavigationController) { - // when presenting a view controller from the menu, the menu view gets moved into another transition view above our transition container - // which can break the visual layout we had before. So, we move the menu view back to its original transition view to preserve it. - if !navigationController.isBeingDismissed() { - if let mainView = navigationController.presentingViewController?.view { - switch SideMenuManager.menuPresentMode { - case .ViewSlideOut: - mainView.superview?.insertSubview(navigationController.view, belowSubview: mainView) - case .MenuSlideIn, .MenuDissolveIn: - mainView.superview?.insertSubview(navigationController.view, aboveSubview: SideMenuManager.tapView) +public class UIMenuNavigationController: UINavigationController { + + @IBInspectable public var leftSide:Bool = false { + didSet { + if isViewLoaded() { // suppress warnings + didSetSide() } } } -} - -private func menuViewDidDisappear(navigationController: UINavigationController) { - // 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 !navigationController.isBeingDismissed() { - navigationController.view.hidden = true - SideMenuManager.hideMenuAppearance() + + override public func viewDidLoad() { + super.viewDidLoad() + + didSetSide() } -} -private func menuViewWillTransitionToSize(navigationController: UINavigationController, size: CGSize, coordinator: UIViewControllerTransitionCoordinator) { - // don't bother resizing if the view isn't visible - if navigationController.view.hidden { - return + private func didSetSide() { + if leftSide { + SideMenuManager.menuLeftNavigationController = self + } else { + SideMenuManager.menuRightNavigationController = self + } } - SideMenuManager.statusBarView?.hidden = true - coordinator.animateAlongsideTransition({ (context) -> Void in - SideMenuManager.presentMenuAppearance(forSize: size) - }) { (context) -> Void in - SideMenuManager.statusBarView?.hidden = false + override public func viewDidAppear(animated: Bool) { + super.viewDidAppear(animated) + + // we had presented a view before, so lets dismiss ourselves as already acted upon + if view.hidden { + SideMenuManager.hideMenuComplete() + dismissViewControllerAnimated(false, completion: { () -> Void in + self.view.hidden = false + }) + } } -} - -private func menuPushViewController(navigationController: UINavigationController, viewController: UIViewController, animated: Bool) { - if let menuViewController: UINavigationController = SideMenuManager.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController { - if let presentingViewController = menuViewController.presentingViewController as? UINavigationController { - - // 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 - navigationController.dismissViewControllerAnimated(true, completion: nil) - navigationController.visibleViewController?.viewWillAppear(false) // Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions - }) - - UIView.animateWithDuration(SideMenuManager.menuAnimationDismissDuration, animations: { () -> Void in - SideMenuManager.hideMenuAppearance() - }) - - if SideMenuManager.menuAllowPopIfPossible { - for subViewController in presentingViewController.viewControllers { - if subViewController.dynamicType == viewController.dynamicType { - presentingViewController.popToViewController(subViewController, animated: animated) + + override public func viewWillDisappear(animated: Bool) { + super.viewWillDisappear(animated) + + // when presenting a view controller from the menu, the menu view gets moved into another transition view above our transition container + // which can break the visual layout we had before. So, we move the menu view back to its original transition view to preserve it. + if !isBeingDismissed() { + if let mainView = presentingViewController?.view { + switch SideMenuManager.menuPresentMode { + case .ViewSlideOut: + mainView.superview?.insertSubview(view, belowSubview: mainView) + case .MenuSlideIn, .MenuDissolveIn: + mainView.superview?.insertSubview(view, aboveSubview: SideMenuManager.tapView) + } + } + } + } + + override public 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.hidden = true + SideMenuManager.hideMenuStart() + } + } + + override public func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) + + // don't bother resizing if the view isn't visible + if view.hidden { + return + } + + SideMenuManager.statusBarView?.hidden = true + coordinator.animateAlongsideTransition({ (context) -> Void in + SideMenuManager.presentMenuStart(forSize: size) + }) { (context) -> Void in + SideMenuManager.statusBarView?.hidden = false + } + } + + override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { + if let menuViewController: UINavigationController = SideMenuManager.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController, + presentingViewController = menuViewController.presentingViewController as? UINavigationController { + presentingViewController.prepareForSegue(segue, sender: sender) + } + } + + override public func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool { + if let menuViewController: UINavigationController = SideMenuManager.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController, + presentingViewController = menuViewController.presentingViewController as? UINavigationController { + return presentingViewController.shouldPerformSegueWithIdentifier(identifier, sender: sender) + } + + return super.shouldPerformSegueWithIdentifier(identifier, sender: sender) + } + + override public func pushViewController(viewController: UIViewController, animated: Bool) { + if let menuViewController: UINavigationController = SideMenuManager.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController { + if let presentingViewController = menuViewController.presentingViewController as? UINavigationController { + + // 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.dismissViewControllerAnimated(true, completion: nil) + self.visibleViewController?.viewWillAppear(false) // Hack: force selection to get cleared on UITableViewControllers when reappearing using custom transitions + }) + + UIView.animateWithDuration(SideMenuManager.menuAnimationDismissDuration, animations: { () -> Void in + SideMenuManager.hideMenuStart() + }) + + if SideMenuManager.menuAllowPopIfPossible { + for subViewController in presentingViewController.viewControllers { + if subViewController.dynamicType == viewController.dynamicType { + presentingViewController.popToViewController(subViewController, animated: animated) + CATransaction.commit() + return + } + } + } + if !SideMenuManager.menuAllowPushOfSameClassTwice { + if presentingViewController.viewControllers.last?.dynamicType == viewController.dynamicType { CATransaction.commit() return } } + + presentingViewController.pushViewController(viewController, animated: animated) + CATransaction.commit() + } else { + menuViewController.presentViewController(viewController, animated: animated, completion: nil) + print("Warning: attempted to push a ViewController from a ViewController that doesn't have a NavigationController. It will be presented it instead.") } - if !SideMenuManager.menuAllowPushOfSameClassTwice { - if presentingViewController.viewControllers.last?.dynamicType == viewController.dynamicType { - CATransaction.commit() - return - } - } - - presentingViewController.pushViewController(viewController, animated: animated) - CATransaction.commit() - } else { - menuViewController.presentViewController(viewController, animated: animated, completion: nil) - print("Warning: attempted to push a ViewController from a ViewController that doesn't have a NavigationController. It will be presented it instead.") } } } -public class UILeftMenuNavigationController: UINavigationController { - - override public func viewDidLoad() { - super.viewDidLoad() - - SideMenuManager.menuLeftNavigationController = self - } - - override public func viewDidAppear(animated: Bool) { - super.viewDidAppear(animated) - - menuViewDidAppear(self) - } - - override public func viewWillDisappear(animated: Bool) { - super.viewWillDisappear(animated) - - menuViewWillDisappear(self) - } - - override public func viewDidDisappear(animated: Bool) { - super.viewDidDisappear(animated) - - menuViewDidDisappear(self) - } - - override public func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { - super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) - - menuViewWillTransitionToSize(self, size: size, coordinator: coordinator) - } - - override public func pushViewController(viewController: UIViewController, animated: Bool) { - menuPushViewController(self, viewController: viewController, animated: animated) - } -} - -public class UIRightMenuNavigationController: UINavigationController { - - override public func viewDidLoad() { - super.viewDidLoad() - - SideMenuManager.menuRightNavigationController = self - } - - override public func viewDidAppear(animated: Bool) { - super.viewDidAppear(animated) - - menuViewDidAppear(self) - } - - override public func viewWillDisappear(animated: Bool) { - super.viewWillDisappear(animated) - - menuViewWillDisappear(self) - } - - override public func viewDidDisappear(animated: Bool) { - super.viewDidDisappear(animated) - - menuViewDidDisappear(self) - } - - override public func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { - super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) - - menuViewWillTransitionToSize(self, size: size, coordinator: coordinator) - } - - override public func pushViewController(viewController: UIViewController, animated: Bool) { - menuPushViewController(self, viewController: viewController, animated: animated) - } -} - public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate { public enum MenuPresentMode { @@ -218,7 +193,7 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro // prevent instantiation private override init() {} - public static var menuLeftNavigationController: UILeftMenuNavigationController? { + public static var menuLeftNavigationController: UIMenuNavigationController? { willSet { if menuLeftNavigationController != nil { let originalBlurEffectStyle = menuBlurEffectStyle @@ -239,7 +214,7 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro } } - public static var menuRightNavigationController: UIRightMenuNavigationController? { + public static var menuRightNavigationController: UIMenuNavigationController? { willSet { if menuRightNavigationController != nil { let originalBlurEffectStyle = menuBlurEffectStyle @@ -464,7 +439,7 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro return viewController } - private class func hideMenuAppearance() { + private class func hideMenuStart() { let mainViewController = viewControllerForPresentedMenu! let menuView = presentDirection == .Left ? menuLeftNavigationController!.view : menuRightNavigationController!.view menuView.transform = CGAffineTransformIdentity @@ -510,7 +485,7 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro } } - private class func presentMenuAppearance(forSize size: CGSize = UIScreen.mainScreen().bounds.size) { + private class func presentMenuStart(forSize size: CGSize = UIScreen.mainScreen().bounds.size) { let mainViewController = viewControllerForPresentedMenu! if let menuView = presentDirection == .Left ? menuLeftNavigationController?.view : menuRightNavigationController?.view { menuView.transform = CGAffineTransformIdentity @@ -574,6 +549,8 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro // animate a change from one viewcontroller to another public func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + let statusBarStyle = SideMenuManager.visibleViewController()?.preferredStatusBarStyle() + // get reference to our fromView, toView and the container view that we should perform the transition in let container = transitionContext.containerView()! if let menuBackgroundColor = SideMenuManager.menuAnimationBackgroundColor { @@ -627,7 +604,7 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro } SideMenuManager.tapView = tapView - SideMenuManager.hideMenuAppearance() // offstage for interactive + SideMenuManager.hideMenuStart() // offstage for interactive NSNotificationCenter.defaultCenter().addObserver(SideMenuManager.singleton, selector:"applicationDidEnterBackgroundNotification", name: UIApplicationDidEnterBackgroundNotification, object: nil) } @@ -637,16 +614,15 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro let options: UIViewAnimationOptions = SideMenuManager.interactive ? .CurveLinear : .CurveEaseInOut UIView.animateWithDuration(duration, delay: 0, options: options, animations: { () -> Void in if SideMenuManager.presenting { - SideMenuManager.presentMenuAppearance() // onstage items: slide in + SideMenuManager.presentMenuStart() // onstage items: slide in } else { - SideMenuManager.hideMenuAppearance() + SideMenuManager.hideMenuStart() } }) { (finished) -> Void in -// if UIApplication.sharedApplication().visibleViewController!.preferredStatusBarStyle() != statusBarStyle { -// // See http://www.openradar.me/21961293 -// print("Warning: do not change the status bar style while using interactive transitions or you risk transitions not properly completing.") -// } + if SideMenuManager.visibleViewController()?.preferredStatusBarStyle() != statusBarStyle { + print("Warning: do not change the status bar style while using custom transitions or you risk transitions not properly completing and locking up the UI. See http://www.openradar.me/21961293") + } // tell our transitionContext object that we've finished animating if transitionContext.transitionWasCancelled() { if SideMenuManager.presenting { @@ -708,7 +684,7 @@ public class SideMenuManager: UIPercentDrivenInteractiveTransition, UIViewContro func applicationDidEnterBackgroundNotification() { if let menuViewController: UINavigationController = SideMenuManager.presentDirection == .Left ? SideMenuManager.menuLeftNavigationController : SideMenuManager.menuRightNavigationController { - SideMenuManager.hideMenuAppearance() + SideMenuManager.hideMenuStart() SideMenuManager.hideMenuComplete() menuViewController.dismissViewControllerAnimated(false, completion: nil) } diff --git a/SideMenu.podspec b/SideMenu.podspec index 5589034..4e11d9f 100644 --- a/SideMenu.podspec +++ b/SideMenu.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "SideMenu" - s.version = "0.1.0" + s.version = "0.1.1" s.summary = "SideMenu is a simple and versatile side menu control." # This description is used to generate tags and improve search results. @@ -21,7 +21,7 @@ Pod::Spec.new do |s| DESC s.homepage = "https://github.com/jonkykong/SideMenu" - # s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" + s.screenshot = "https://raw.githubusercontent.com/jonkykong/SideMenu/master/etc/Preview.gif" s.license = 'MIT' s.author = { "jonkykong" => "jonk@jonked.com" } s.source = { :git => "https://github.com/jonkykong/SideMenu.git", :tag => s.version.to_s }