AKSideMenu is a double side menu library with parallax effect.
See the contained examples to get a sample of how AKSideMenu can easily be integrated in your project.
Build the examples from the AKSideMenuExamples directory.
To install, add the following line to your Podfile:
pod 'AKSideMenu'To install, add the following line to your Cartfile:
github "dogo/AKSideMenu" "1.4.7"In your AppDelegate, add the code below.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
// Create content and menu controllers
let navigationController = UINavigationController(rootViewController: FirstViewController())
let leftMenuViewController = LeftMenuViewController()
let rightMenuViewController = RightMenuViewController()
// Create side menu controller
let sideMenuViewController = AKSideMenu(contentViewController: navigationController, leftMenuViewController: leftMenuViewController, rightMenuViewController: rightMenuViewController)
// Make it a root controller
window?.rootViewController = sideMenuViewController
window?.backgroundColor = .white
window?.makeKeyAndVisible()
return true
} - Create a subclass of
AKSideMenu. In this example we call itRootViewController. - In the Storyboard designate the root view's owner as
RootViewController. - Add more view controllers to your Storyboard, and give them identifiers "leftMenuViewController", "rightMenuViewController" and "contentViewController". Note that in the new XCode the identifier is called "Storyboard ID" and can be found in the Identity inspector.
- Add a method
awakeFromNibtoRootViewController.swiftwith the following code:
override public func awakeFromNib() {
contentViewController = storyboard!.instantiateViewController(withIdentifier: "contentViewController")
leftMenuViewController = storyboard!.instantiateViewController(withIdentifier: "leftMenuViewController")
rightMenuViewController = storyboard!.instantiateViewController(withIdentifier: "rightMenuViewController")
}Here is an example of a delegate implementation. Please adapt the code to your context.
...
sideMenuViewController.delegate = self
...
// MARK: - <AKSideMenuDelegate>
open func sideMenu(_ sideMenu: AKSideMenu, shouldRecognizeGesture recognizer: UIGestureRecognizer, simultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// return true to allow both gesture recognizers to recognize simultaneously. Returns false by default
return false
}
open func sideMenu(_ sideMenu: AKSideMenu, gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// return true or false based on your failure requirements. Returns false by default
return false
}
open func sideMenu(_ sideMenu: AKSideMenu, gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailBy otherGestureRecognizer: UIGestureRecognizer) -> Bool {
// return true or false based on your failure requirements. Returns false by default
return false
}
open func sideMenu(_ sideMenu: AKSideMenu, willShowMenuViewController menuViewController: UIViewController) {
print("willShowMenuViewController")
}
open func sideMenu(_ sideMenu: AKSideMenu, didShowMenuViewController menuViewController: UIViewController) {
print("didShowMenuViewController")
}
open func sideMenu(_ sideMenu: AKSideMenu, willHideMenuViewController menuViewController: UIViewController) {
print("willHideMenuViewController")
}
open func sideMenu(_ sideMenu: AKSideMenu, didHideMenuViewController menuViewController: UIViewController) {
print("didHideMenuViewController")
}Present the menu view controller:
self.sideMenuViewController!.presentLeftMenuViewController()or
self.sideMenuViewController!.presentRightMenuViewController()Switch content view controllers:
self.sideMenuViewController!.setContentViewController(viewController, animated: true)
self.sideMenuViewController!.hideMenuViewController()public var animationDuration: TimeIntervalThe animation duration. Defaults to 0.35.
public var backgroundImage: UIImageThe content background image. Defaults to white.
public var panGestureEnabled: BoolEnables panGesture detection. Defaults to True.
public var panFromEdge: BoolEnables panGesture detection from the edge. Defaults to True.
public var panMinimumOpenThreshold: FloatThe minimum pan gesture amount to open the side menu. Defaults to 60.0.
public var interactivePopGestureRecognizerEnabled: BoolEnables interactive pop gesture recognizer. Defaults to True.
public var scaleContentView: BoolScales the content view down when a menu is visible. Defaults to True.
public var scaleBackgroundImageView: BoolScales the background image view before the menu is opened, then animates it back to its normal size while presenting the menu. Defaults to True.
public var scaleMenuView: BoolScales the menu view during menu presentation. Defaults to True.
public var contentViewShadowEnabled: BoolShows a shadow around the content view while the menu is visible. Defaults to False.
public var contentViewShadowOffset: CGSizeSets the content view shadow offset. Defaults to CGSizeZero.
public var contentViewShadowOpacity: FloatSets the content view shadow opacity. Defaults to 0.4.
public var contentViewShadowRadius: CGFloatSets the content view shadow blur radius. Defaults to 8.0.
public var contentViewScaleValue: CGFloatSets the scale applied to the content view when a menu is visible. Defaults to 0.7.
public var contentViewInLandscapeOffsetCenterX: CGFloatSets the horizontal center offset applied to the content view in landscape orientation when a menu is visible. Defaults to 30.0.
public var contentViewInPortraitOffsetCenterX: CGFloatSets the horizontal center offset applied to the content view in portrait orientation when a menu is visible. Defaults to 30.0.
public var parallaxMenuMinimumRelativeValue: CGFloatSets the minimum relative value for menu view parallax motion effects. Defaults to -15.
public var parallaxMenuMaximumRelativeValue: CGFloatSets the maximum relative value for menu view parallax motion effects. Defaults to 15.
public var parallaxContentMinimumRelativeValue: CGFloatSets the minimum relative value for content view parallax motion effects. Defaults to -25.
public var parallaxContentMaximumRelativeValue: CGFloatSets the maximum relative value for content view parallax motion effects. Defaults to 25.
public var menuViewControllerTransformation: CGAffineTransform?Sets the initial transform applied to the menu view before it is animated into place. Defaults to CGAffineTransform(scaleX: 1.5, y: 1.5).
public var parallaxEnabled: BoolEnables motion-effect parallax for the menu and content views. Defaults to True.
public var bouncesHorizontally: BoolAllows horizontal pan gestures to move past the fully opened menu position. Defaults to True.
public var menuPreferredStatusBarStyle: UIStatusBarStylePreferred UIStatusBarStyle when the menu is visible. Defaults to UIStatusBarStyle.default.
public var menuPrefersStatusBarHidden: BoolSets StatusBar hidden or not when the menu is visible. Defaults to False.
public var backgroundTransformScale: CGFloatSets the transform scale amount applied to the background imageview. Defaults to 1.7.
public var panFromEdgeZoneWidth: CGFloatSets the width of the pan gesture zone should be recognized. Defaults to 20.0.
public var panGestureLeftEnabled: BoolEnable or disable left pan gesture recognition. Defaults to True.
public var panGestureRightEnabled: BoolEnable or disable right pan gesture recognition. Defaults to True.
I tried to build an easy way to use API, while being flexible enough for multiple variations, but I'm sure there are ways of improving and adding more features, so feel free to collaborate with ideas, issues and/or pull requests.
AKSideMenu needs ARC.
AKSideMenu is available under the MIT license.
Roman Efimov @romaonthego

