From 024169558f68eda59c7a34269595124aca38beea Mon Sep 17 00:00:00 2001 From: Aryan Ghassemi Date: Sun, 26 Jan 2014 20:06:53 -0800 Subject: [PATCH] Update README.md --- README.md | 101 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 11e1b52..fea9881 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ iOS-Slide-Menu -============== +--------- iOS Slide Menu built on top of UINavigationController. @@ -9,9 +9,16 @@ Features: - Configurable Buttons - Allows Enable/Disable menu by implmenting delegate methods - Tap/Swipe gesture recognizer to Open/Close the Menus +- Allows custom animation ![alt tag](https://raw.github.com/aryaxt/iOS-Slide-Menu/master/slideMenuAnimation.gif) +Version 1.3.0 Notes +--------- +If you are updating from previous versions you'll get compile errors, due to changes to RevealAnimations. +Animation configuration is now handled differently, and is separated from the SlideNavigationController. +Please see bwlow for more information. + Setup --------- ``` @@ -36,6 +43,7 @@ SomeViewController *vc = [[SomeViewController alloc] init]; ``` Configuring Left and Right menu for different Viewcontrollers --------- +You decide whether to enable or disable slide functionality on each viewController by implementing the following delegate methods of SlideNavigationControllerDelegate. These methods are optional, and if not implemented the menu functionality will be disabled for that particulat viewController. ``` @interface MyViewController : UIViewController @end @@ -56,34 +64,83 @@ Configuring Left and Right menu for different Viewcontrollers @end ``` -Configuring menu offset +Public properties --------- -Menu offset can be configured for both portrait and landscape mode +###### avoidSwitchingToSameClassViewController +Default value is set to YES. +If set to YES when switching to a new ViewController if the new viewcontroller is the same type as the current viewcontroller it'll close the menu instead of switching to the viewController. + +If set to NO it'll switch to the viewController regardless of types + +This can be usefull when you have a menu item, and when the user selects an already selected menu item you don't want to navigate to a new instance of the viewController +###### enableSwipeGesture +When set to YES user can swipe to open the menu + +When set to NO swipe is disabled, and use can only open the menu using the UIBarButtonItem added to the navigationBar +###### rightMenu +The viewController of the right menu in the navigationController +###### leftMenu +The viewController of the left menu in the navigationController +###### leftBarButtonItem +Default value is null. When this button is set navigationController uses this UIBarButtonItem as the leftItem. this property is intended to be used when a custom UIBarButton is needed (UIBarButtonItem initialized with a custom view) +###### rightBarButtonItem +Behaves exactly the same as leftbarButtonItem, but it's used as the right button for the menu +###### portraitSlideOffset +Default value of portraitSlideOffset is 60. This means when the menu is open, the width of the visible portion of the navigation controller is 60 pixels in portrait mode +###### landscapeSlideOffset +Default value of portraitSlideOffset is 60. This means when the menu is open, the width of the visible portion of the navigation controller is 60 pixels in landscape mode +###### menuRevealAnimator +menuRevealAnimator is used to animate the left/right menu during reveal. The default value is nil that means no animations occure when opening/closing the menu. + +There are existing animation that can be used out of the box. These animation classes can be configured through init method options. + +- SlideNavigationContorllerAnimatorSlide +- SlideNavigationContorllerAnimatorFade +- SlideNavigationContorllerAnimatorScale +- SlideNavigationContorllerAnimatorScaleAndFade +- SlideNavigationContorllerAnimatorSlideAndFade + ``` -[SlideNavigationController sharedInstance].landscapeSlideOffset = 400; -[SlideNavigationController sharedInstance].portraitSlideOffset = 60; +SlideNavigationContorllerAnimatorSlideAndFade *alideAndFadeAnimator = [[SlideNavigationContorllerAnimatorSlideAndFade alloc] initWithMaximumFadeAlpha:.8 fadeColor:[UIColor redColor] andSlideMovement:100]; +[SlideNavigationController sharedInstance].menuRevealAnimator = alideAndFadeAnimator; ``` -Menu Reveal Animations +Custom Animations --------- -There are three types of animations that can be applied when revealing the menu +SlideNavigationController allows custom reveal animations. In order to add custom animations create a new class implementing SlideNavigationContorllerAnimator protocol. For more information take a look at the existing animation classes. +###### - (void)prepareMenuForAnimation:(Menu)menu; +This method gets called right before the menu is about to reveal +###### - (void)animateMenu:(Menu)menu withProgress:(CGFloat)progress; +This method gets called as the menu reveal occurs, and passes the progress to be used for animations(progress is between 0 and 1) +###### - (void)clear; +This method gets called if for any resons the instance of animator is being changed. For instance, the animator is changed from SlideNavigationContorllerAnimatorFade to SlideNavigationContorllerAnimatorSlide. In this method you should cleanup the state of the menu if neede. For instance if you added a view to the menu for reveal animation, you should remove it when clear gets called. +Public Methods +--------- +###### + (SlideNavigationController *)sharedInstance; +Returns the singleton instance of SlideNavigationController + +###### - (void)switchToViewController:(UIViewController *)viewController withCompletion:(void (^)())completion; +Pops to root ViewController, then pushes the new ViewController and finally calls the completion + +###### - (void)openMenu:(Menu)menu withCompletion:(void (^)())completion; +Opens a given menu and calls the completion block oppon animation completion + +###### - (void)closeMenuWithCompletion:(void (^)())completion; +Closes the menu and calls the completion block oppon animation completion + +###### - (void)toggleLeftMenu; +Toggles the left menu open or close depending on the existing state. This was made public in order to pass the selector to a custom UIBarButtonItem (ex: UIBarButtonItem with a button as a custom view) ``` -MenuRevealAnimationNone -MenuRevealAnimationFade -MenuRevealAnimationSlide -MenuRevealAnimationSlideAndFade - -[SlideNavigationController sharedInstance].menuRevealAnimation = MenuRevealAnimationSlideAndFade; +UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; +[button setImage:[UIImage imageNamed:@"menu-button"] forState:UIControlStateNormal]; +[button addTarget:[SlideNavigationController sharedInstance] action:@selector(toggleRightMenu) forControlEvents:UIControlEventTouchUpInside]; +UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; +[SlideNavigationController sharedInstance].rightBarButtonItem = rightBarButtonItem; ``` -The opacity applied during a fade animation can be configured using a property on SlideNavigationController called menuRevealAnimationFadeMaximumAlpha. This value can be anywhere between 0 and 1, and it represents the darkes a menu can become. The color of fade layer can also be configured using the property called menuRevealAnimationFadeColor -``` -[SlideNavigationController sharedInstance].menuRevealAnimationFadeColor = [UIColor greenColor]; -[SlideNavigationController sharedInstance].menuRevealAnimationFadeMaximumAlpha = .5; -``` +###### - (void)toggleRightMenu; +Works exactly the same as toggleLeftMenu, but used to toggle left menu -The movement of menu during a slide animation can also be configured -``` -[SlideNavigationController sharedInstance].menuRevealAnimationSlideMovement = 50; -``` +###### - (BOOL)isMenuOpen; +Returns a boolean stating whether the menu is open or not