From 67f9377ae61ab84f19089da5d3ea017312eda5fd Mon Sep 17 00:00:00 2001 From: "stefano.antonelli" Date: Tue, 19 Feb 2013 11:05:57 +0100 Subject: [PATCH] Fixed issues #41,#40,#38,#33: https://github.com/stefanoa/SASlideMenu/issues/41 https://github.com/stefanoa/SASlideMenu/issues/40 https://github.com/stefanoa/SASlideMenu/issues/38 https://github.com/stefanoa/SASlideMenu/issues/33 --- CHANGELOG.md | 7 + README.md | 9 +- SASlideMenu.xcodeproj/project.pbxproj | 22 +- SASlideMenu/ColoredDetailViewController.h | 2 +- .../ExampleDynamicMenuViewController.m | 38 +- SASlideMenu/ExampleStaticMenuViewController.m | 30 +- .../SASlideMenu/SASlideMenuContentSegue.m | 25 +- .../SASlideMenu/SASlideMenuDataSource.h | 30 +- .../SASlideMenu/SASlideMenuLeftMenuSegue.m | 8 +- .../SASlideMenuNavigationController.m | 2 +- .../SASlideMenu/SASlideMenuPushSegue.m | 2 +- .../SASlideMenuRootViewController.h | 9 +- .../SASlideMenuRootViewController.m | 27 +- .../SASlideMenu/SASlideMenuViewController.h | 3 +- .../SASlideMenu/SASlideMenuViewController.m | 41 +- .../en.lproj/MainStoryboard.storyboard | 398 +++++++++++------- SASlideMenuStatic/LightViewController.h | 17 + SASlideMenuStatic/LightViewController.m | 20 + .../en.lproj/MainStoryboard.storyboard | 51 ++- 19 files changed, 504 insertions(+), 237 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 SASlideMenuStatic/LightViewController.h create mode 100644 SASlideMenuStatic/LightViewController.m diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..3b7e90b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# CHANGELOG + +Version 1.2.0 +* Fixed issues #41,#40,#38,#33 +* Changes to SASlideMenuDataSource +* SASlideMenuStatic example now cache the content view controllers +* Added CHANGELOG.md diff --git a/README.md b/README.md index e9d7204..dcb921d 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,16 @@ The repository is an Xcode 4 project that contains two example of the usage of t # Usage You can use SASlide menu with both static cells and dynamic cell prototypes. In the project yuo will find two different target that use both type of cells to create a slide menu. To use it in your project follow these steps: +* Add the SASlideMenu subdir and it's contents to your project +* Add a new class that inherits from **SASlideMenuViewController** and include/implement **SASlideMenuDataSource** and **SASlideMenuDelegate**. + * **SASlideMenuDataSource** is where you will code your customization while **SASlideMenuDelegate** is where you will add your code to implement the behavior of your app related to the **SASlideMenu** events. -* Add the SASlideMenu subdir and his content to your project -* Add a new class that inherit from **SASlideMenuViewController** and implement **SASlideMenuDatSource** and **SASlideMenuDelegate**. **SASlideMenuDataSource** is where you will code your customization while **SASlideMenuDelegate** is where you will add your code to implement the behavior of your app related to the SASlideMenu events. There are a minimum **SASlideMenuDataSource** methods that are required while the **SASlideMenuDelegate** is entirely optional. * Add a new **SASlideMenuRootViewController** in your storyboard * Add a **UITableViewController** and make it of the **SASlideMenuViewController** subclass you already implemented and customize it in accordance with your needs. * Connect the **SASlideMenuRootViewController** with your subclass with a custom segue of type **SASlideMenuLeftMenuSegue**, set the segue identifier to **leftMenu**. * To add Content ViewController you have to to do the following: * Create your content view controller and embed it in a **UINavigationController** - * Connet it to the SASlideMenuViewController via a SASlideMenuContentSegue. If you are using static cells simply connect from the corresponding cell. If you are using dynamic cell prototype connect it from the VieController and assign an identifier that will be returned in the **sugueIdForIndexPath:** method linked to the desired indexPath. + * Connet it to the **SASlideMenuViewController** via a SASlideMenuContentSegue. If you are using static cells and you simply connect from the corresponding cell it is not possible to cache the content view controller and the **segueIdForIndexPath** must not be implemented. If you are using dynamic cell prototype or you are using static cells and you want to cache the content view controller, assign an identifier that will be returned in the **sugueIdForIndexPath:** method linked to the desired indexPath. * To add a right menu, connect a new **UINavigationController** containing a **UITableViewController** to the menu view controller using a **SASlideMenuRightMenuSegue** and set the segue identifier to **rightMenu**. The new view controller will contain the right menu and will allow navigation. Test it and you are done! @@ -55,4 +56,4 @@ It needs iOS 5.1 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER* *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,* *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN* -*THE SOFTWARE.* \ No newline at end of file +*THE SOFTWARE.* diff --git a/SASlideMenu.xcodeproj/project.pbxproj b/SASlideMenu.xcodeproj/project.pbxproj index 9096962..da8ba46 100644 --- a/SASlideMenu.xcodeproj/project.pbxproj +++ b/SASlideMenu.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 7B27435A16D2820600F89C69 /* LightViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B27435916D2820600F89C69 /* LightViewController.m */; }; + 7B27435C16D3638300F89C69 /* CHANGELOG.md in Resources */ = {isa = PBXBuildFile; fileRef = 7B27435B16D3638300F89C69 /* CHANGELOG.md */; }; 7BC688BF16A6FD08004ED00D /* SASlideMenuRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC688BE16A6FD08004ED00D /* SASlideMenuRootViewController.m */; }; 7BC688FC16A99DB2004ED00D /* SASlideMenuContentSegue.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC688F416A99DA3004ED00D /* SASlideMenuContentSegue.m */; }; 7BC688FD16A99DB2004ED00D /* SASlideMenuLeftMenuSegue.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC688F616A99DA3004ED00D /* SASlideMenuLeftMenuSegue.m */; }; @@ -121,6 +123,9 @@ 7B1141A4161B621000549B42 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 7B1141A7161B658D00549B42 /* Screenshot-Landscape.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Screenshot-Landscape.png"; sourceTree = ""; }; 7B1141A8161B658D00549B42 /* Screenshot-Portrait.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Screenshot-Portrait.png"; sourceTree = ""; }; + 7B27435816D2820600F89C69 /* LightViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LightViewController.h; sourceTree = ""; }; + 7B27435916D2820600F89C69 /* LightViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LightViewController.m; sourceTree = ""; }; + 7B27435B16D3638300F89C69 /* CHANGELOG.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CHANGELOG.md; sourceTree = ""; }; 7B28D2A2165BF464000EE929 /* ExampleDynamicMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExampleDynamicMenuViewController.h; path = ../SASlideMenu/ExampleDynamicMenuViewController.h; sourceTree = ""; }; 7B28D2A3165BF464000EE929 /* ExampleDynamicMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ExampleDynamicMenuViewController.m; path = ../SASlideMenu/ExampleDynamicMenuViewController.m; sourceTree = ""; }; 7B28D2A5165CCB10000EE929 /* ColoredViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ColoredViewController.h; path = ../SASlideMenu/ColoredViewController.h; sourceTree = ""; }; @@ -277,6 +282,7 @@ 7B56BF48163C2ECF00D9C143 /* Icon.png */, 7B1141A4161B621000549B42 /* Default-568h@2x.png */, 7BF0A6B915DE682A00B3B57F /* README.md */, + 7B27435B16D3638300F89C69 /* CHANGELOG.md */, 7B8C3FE415D8D55800E42A41 /* SASlideMenu */, 7BDBF427166CC79300FDA327 /* SASlideMenuDynamic */, 7BDBF46F166CDEB100FDA327 /* SASlideMenuStatic */, @@ -367,6 +373,8 @@ 7BF0A6B115DE499F00B3B57F /* MenuCell.m */, 7B3B2D5215DCE0E1009F4AB8 /* DarkViewController.h */, 7B3B2D5315DCE0E1009F4AB8 /* DarkViewController.m */, + 7B27435816D2820600F89C69 /* LightViewController.h */, + 7B27435916D2820600F89C69 /* LightViewController.m */, 7B5B88E1163B23B300D02C1F /* ShadesViewController.h */, 7B5B88E2163B23B300D02C1F /* ShadesViewController.m */, 7B8C3FF315D8D55800E42A41 /* ExampleStaticMenuViewController.h */, @@ -396,6 +404,8 @@ 7BF0A68615DE492E00B3B57F /* SASlideMenu */ = { isa = PBXGroup; children = ( + 7BF0A68915DE495500B3B57F /* SASlideMenuDataSource.h */, + 7B5CA6EE1682121B006E6993 /* SASlideMenuDelegate.h */, 7BC688F316A99DA3004ED00D /* SASlideMenuContentSegue.h */, 7BC688F416A99DA3004ED00D /* SASlideMenuContentSegue.m */, 7BC688F516A99DA3004ED00D /* SASlideMenuLeftMenuSegue.h */, @@ -406,8 +416,6 @@ 7BFEA28616C0FACF00455A22 /* SASlideMenuPushSegue.m */, 7BC688F716A99DA4004ED00D /* SASlideMenuViewController.h */, 7BC688F816A99DA4004ED00D /* SASlideMenuViewController.m */, - 7BF0A68915DE495500B3B57F /* SASlideMenuDataSource.h */, - 7B5CA6EE1682121B006E6993 /* SASlideMenuDelegate.h */, 7BC688BD16A6FD08004ED00D /* SASlideMenuRootViewController.h */, 7BC688BE16A6FD08004ED00D /* SASlideMenuRootViewController.m */, 7BFEA28816C1545000455A22 /* SASlideMenuRightMenuViewController.h */, @@ -462,7 +470,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = SASlideMenu; - LastUpgradeCheck = 0440; + LastUpgradeCheck = 0460; ORGANIZATIONNAME = "Stefano Antonelli"; }; buildConfigurationList = 7B8C3FD415D8D55800E42A41 /* Build configuration list for PBXProject "SASlideMenu" */; @@ -565,6 +573,7 @@ 7BDBF4AA166CDF8200FDA327 /* rowselected@2x.png in Resources */, 7BDBF4B1166CE51200FDA327 /* Icon.png in Resources */, 7BDBF4B2166CE51900FDA327 /* Icon@2x.png in Resources */, + 7B27435C16D3638300F89C69 /* CHANGELOG.md in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -608,6 +617,7 @@ 7BC688FE16A99DB2004ED00D /* SASlideMenuViewController.m in Sources */, 7BC6890216A9F51C004ED00D /* SASlideMenuRootViewController.m in Sources */, 7BFEA28E16C2573F00455A22 /* SASlideMenuNavigationController.m in Sources */, + 7B27435A16D2820600F89C69 /* LightViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -664,6 +674,9 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; @@ -691,6 +704,9 @@ ARCHS = "$(ARCHS_STANDARD_32_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; diff --git a/SASlideMenu/ColoredDetailViewController.h b/SASlideMenu/ColoredDetailViewController.h index 68f8cd8..001240a 100644 --- a/SASlideMenu/ColoredDetailViewController.h +++ b/SASlideMenu/ColoredDetailViewController.h @@ -8,7 +8,7 @@ #import -@interface ColoredDetailViewController : UIViewController +@interface ColoredDetailViewController : UITableViewController @property(nonatomic,strong) IBOutlet UIView* colorBox; @property(nonatomic,strong) IBOutlet UILabel* hue; @property(nonatomic,strong) IBOutlet UILabel* brightness; diff --git a/SASlideMenu/ExampleDynamicMenuViewController.m b/SASlideMenu/ExampleDynamicMenuViewController.m index 8f21029..94d4f21 100644 --- a/SASlideMenu/ExampleDynamicMenuViewController.m +++ b/SASlideMenu/ExampleDynamicMenuViewController.m @@ -27,8 +27,7 @@ -(id) initWithCoder:(NSCoder *)aDecoder{ self.slideMenuDataSource = self; self.slideMenuDelegate = self; self.selectedBrightness = 0.3; - self.selectedHue = 0.0; - + self.selectedHue = 0.0; } return self; } @@ -50,19 +49,16 @@ -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface return YES; } --(void) prepareForSwitchToContentViewController:(UIViewController *)content{ - UINavigationController* navigationController = (UINavigationController*)content; - ColoredViewController* coloredViewController = (ColoredViewController*) navigationController.topViewController; - - [coloredViewController setBackgroundHue:selectedHue brightness:selectedBrightness]; -} #pragma mark - #pragma mark SASlideMenuDataSource -// The SASlideMenuDataSource provides the initial segueid that represents the initial visibile view controller, the eventual additional configuration to the menu button and the mapping for each indexPath to the segues for the content controllers - - - +-(void) prepareForSwitchToContentViewController:(UINavigationController *)content{ + UIViewController* controller = [content.viewControllers objectAtIndex:0]; + if ([controller isKindOfClass:[ColoredViewController class]]) { + ColoredViewController* coloredViewController = (ColoredViewController*) controller; + [coloredViewController setBackgroundHue:selectedHue brightness:selectedBrightness]; + } +} // It configure the menu button. The beahviour of the button should not be modified -(void) configureMenuButton:(UIButton *)menuButton{ @@ -74,6 +70,7 @@ -(void) configureMenuButton:(UIButton *)menuButton{ [menuButton setAdjustsImageWhenDisabled:NO]; } +// It configure the right menu button. The beahviour of the button should not be modified -(void) configureRightMenuButton:(UIButton *)menuButton{ menuButton.frame = CGRectMake(0, 0, 40, 29); [menuButton setImage:[UIImage imageNamed:@"menuright.png"] forState:UIControlStateNormal]; @@ -82,9 +79,10 @@ -(void) configureRightMenuButton:(UIButton *)menuButton{ [menuButton setAdjustsImageWhenHighlighted:NO]; [menuButton setAdjustsImageWhenDisabled:NO]; } + // This is the segue you want visibile when the controller is loaded the first time --(NSString*) initialSegueId{ - return @"colored"; +-(NSIndexPath*) selectedIndexPath{ + return [NSIndexPath indexPathForRow:0 inSection:0]; } // It maps each indexPath to the segueId to be used. The segue is performed only the first time the controller needs to loaded, subsequent switch to the content controller will use the already loaded controller @@ -95,9 +93,11 @@ -(NSString*) segueIdForIndexPath:(NSIndexPath *)indexPath{ } return @"colored"; } + -(Boolean) slideOutThenIn{ return NO; } +//Enable caching for the Controller at the provided indexPath -(Boolean) allowContentViewControllerCachingForIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row ==0) { return NO; @@ -105,11 +105,13 @@ -(Boolean) allowContentViewControllerCachingForIndexPath:(NSIndexPath *)indexPat return YES; } --(Boolean) hasRightMenuForSegueId:(NSString *)segueId{ - if ([segueId isEqualToString:@"coloredNoRightMenu"]) { - return NO; +//Enable the right menu for the controller linked to the Segue indentified by the provided segueId +-(Boolean) hasRightMenuForIndexPath:(NSIndexPath *)indexPath{ + + if (indexPath.section == 0) { + return YES; } - return YES; + return NO; } #pragma mark - diff --git a/SASlideMenu/ExampleStaticMenuViewController.m b/SASlideMenu/ExampleStaticMenuViewController.m index 7e9151c..cac7eff 100644 --- a/SASlideMenu/ExampleStaticMenuViewController.m +++ b/SASlideMenu/ExampleStaticMenuViewController.m @@ -11,7 +11,7 @@ #import "ExampleStaticMenuViewController.h" #import "MenuCell.h" #import "DarkViewController.h" - +#import "LightViewController.h" @interface ExampleStaticMenuViewController () @end @@ -44,9 +44,23 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface #pragma mark SASlideMenuDataSource // The SASlideMenuDataSource is used to provide the initial segueid that represents the initial visibile view controller and to provide eventual additional configuration to the menu button -// This is the segue you want visibile when the controller is loaded the first time --(NSString*) initialSegueId{ - return @"dark"; +// This is the indexPath selected at start-up +-(NSIndexPath*) selectedIndexPath{ + return [NSIndexPath indexPathForRow:0 inSection:0]; +} + +-(NSString*) segueIdForIndexPath:(NSIndexPath *)indexPath{ + if (indexPath.row == 0) { + return @"dark"; + }else if (indexPath.row == 1){ + return @"light"; + }else{ + return @"shades"; + } +} + +-(Boolean) allowContentViewControllerCachingForIndexPath:(NSIndexPath *)indexPath{ + return YES; } // This is used to configure the menu button. The beahviour of the button should not be modified @@ -71,7 +85,13 @@ -(void) configureSlideLayer:(CALayer *)layer{ -(CGFloat) leftMenuVisibleWidth{ return 280; } - +-(void) prepareForSwitchToContentViewController:(UINavigationController *)content{ + UIViewController* controller = [content.viewControllers objectAtIndex:0]; + if ([controller isKindOfClass:[LightViewController class]]) { + LightViewController* lightViewController = (LightViewController*)controller; + lightViewController.menuViewController = self; + } +} #pragma mark - #pragma mark SASlideMenuDelegate diff --git a/SASlideMenu/SASlideMenu/SASlideMenuContentSegue.m b/SASlideMenu/SASlideMenu/SASlideMenuContentSegue.m index fa878cf..6d3f47f 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuContentSegue.m +++ b/SASlideMenu/SASlideMenu/SASlideMenuContentSegue.m @@ -26,12 +26,14 @@ -(void) perform{ navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuButton]; Boolean hasRightMenu = NO; + rootController.isRightMenuEnabled = NO; NSIndexPath* selectedIndexPath = [rootController.leftMenu.tableView indexPathForSelectedRow]; - if ([rootController.leftMenu.slideMenuDataSource respondsToSelector:@selector(hasRightMenuForSegueId:)]) { - hasRightMenu = [rootController.leftMenu.slideMenuDataSource hasRightMenuForSegueId:self.identifier]; + if ([rootController.leftMenu.slideMenuDataSource respondsToSelector:@selector(hasRightMenuForIndexPath:)]) { + hasRightMenu = [rootController.leftMenu.slideMenuDataSource hasRightMenuForIndexPath:selectedIndexPath]; } if (hasRightMenu) { + rootController.isRightMenuEnabled = YES; if ([rootController.leftMenu.slideMenuDataSource respondsToSelector:@selector(configureRightMenuButton:)]) { UIButton* rightMenuButton = [[UIButton alloc] init]; [rootController.leftMenu.slideMenuDataSource configureRightMenuButton:rightMenuButton]; @@ -56,19 +58,16 @@ -(void) perform{ [rootController switchToContentViewController:destination]; - if ([rootController.leftMenu.slideMenuDataSource respondsToSelector:@selector(sugueIdForIndexPath:)]) { + if ([rootController.leftMenu.slideMenuDataSource respondsToSelector:@selector(segueIdForIndexPath:)]) { [rootController addContentViewController:destination withIndexPath:selectedIndexPath]; } - if ([rootController.leftMenu.slideMenuDataSource respondsToSelector:@selector(hasRightMenuForSegueId:)]) { - Boolean hasRightMenu = [rootController.leftMenu.slideMenuDataSource hasRightMenuForSegueId:self.identifier]; - if (hasRightMenu) { - rootController.isRightMenuEnabled = YES; - }else{ - rootController.isRightMenuEnabled = NO; - } - }else{ - rootController.isRightMenuEnabled = NO; - } + + UIPanGestureRecognizer* panGesture= [[UIPanGestureRecognizer alloc] initWithTarget:rootController action:@selector(panItem:)]; + [panGesture setMaximumNumberOfTouches:2]; + [panGesture setDelegate:source]; + [panGesture setCancelsTouchesInView:NO]; + + [destination.view addGestureRecognizer:panGesture]; } @end diff --git a/SASlideMenu/SASlideMenu/SASlideMenuDataSource.h b/SASlideMenu/SASlideMenu/SASlideMenuDataSource.h index 35ba1c6..82a738a 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuDataSource.h +++ b/SASlideMenu/SASlideMenu/SASlideMenuDataSource.h @@ -6,27 +6,43 @@ // Copyright (c) 2012 Stefano Antonelli. All rights reserved. // -#import @protocol SASlideMenuDataSource -@required --(NSString*) initialSegueId; --(void) configureMenuButton:(UIButton*) menuButton; - @optional --(void) prepareForSwitchToContentViewController:(UIViewController *)content; +//It is used to prepare the Content View Controller before it will be displayed. +//It is called for each selection of the menu. +-(void) prepareForSwitchToContentViewController:(UINavigationController *)content; + +//Maps menu rows to segueId. It is a required method for table with dynamic cell prototype. +//It is also required if you want to use static table but you need to cache content view controllers. -(NSString*) segueIdForIndexPath:(NSIndexPath*) indexPath; --(Boolean) hasRightMenuForSegueId:(NSString*) segueId; +//It returns the initially selected menu row. If not implemented the menu is initially displayed without selection. +-(NSIndexPath*) selectedIndexPath; + +// It is used to provide a custom configuration for the menu button. +-(void) configureMenuButton:(UIButton*) menuButton; + +// It is used to selectively activate the right menu button. It is a mandatory method if you need a right button. +-(Boolean) hasRightMenuForIndexPath:(NSIndexPath*) indexPath; +// It is used to provide a custom configuration for the right menu button. It is a mandatory method if you need a right button. -(void) configureRightMenuButton:(UIButton*) menuButton; + +// It is used to provide a custom configuration for the content CALayer, useful to change shadow style. -(void) configureSlideLayer:(CALayer*) layer; +// The visibile widht of the left menu -(CGFloat) leftMenuVisibleWidth; + +// The visibile widht of the right menu -(CGFloat) rightMenuVisibleWidth; +// If it returns true when switching between content view controller the deselected one will slide out before the selected one will slide in. -(Boolean) slideOutThenIn; +// It is used to selectively allow content view controller caching. -(Boolean) allowContentViewControllerCachingForIndexPath:(NSIndexPath*) indexPath; + @end diff --git a/SASlideMenu/SASlideMenu/SASlideMenuLeftMenuSegue.m b/SASlideMenu/SASlideMenu/SASlideMenuLeftMenuSegue.m index 5033134..bad29ff 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuLeftMenuSegue.m +++ b/SASlideMenu/SASlideMenu/SASlideMenuLeftMenuSegue.m @@ -29,8 +29,12 @@ -(void) perform{ } completion:^(BOOL finished) { [leftMenu didMoveToParentViewController:rootViewController]; - NSString* initiaSegueId = [rootViewController.leftMenu.slideMenuDataSource initialSegueId]; - [leftMenu performSegueWithIdentifier:initiaSegueId sender:leftMenu]; + if ([rootViewController.leftMenu.slideMenuDataSource respondsToSelector:@selector(selectedIndexPath)]) { + NSIndexPath* selectedIndexPath = [rootViewController.leftMenu.slideMenuDataSource selectedIndexPath]; + [leftMenu.tableView selectRowAtIndexPath:selectedIndexPath animated:NO scrollPosition:UITableViewScrollPositionTop]; + NSString* initialSegueId = [rootViewController.leftMenu.slideMenuDataSource segueIdForIndexPath:selectedIndexPath]; + [leftMenu performSegueWithIdentifier:initialSegueId sender:leftMenu]; + } }]; } diff --git a/SASlideMenu/SASlideMenu/SASlideMenuNavigationController.m b/SASlideMenu/SASlideMenu/SASlideMenuNavigationController.m index e5268c6..a2bbc41 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuNavigationController.m +++ b/SASlideMenu/SASlideMenu/SASlideMenuNavigationController.m @@ -16,7 +16,7 @@ @implementation SASlideMenuNavigationController -(UIViewController *)popViewControllerAnimated:(BOOL)animated{ if (self.topViewController == self.lastController) { - [self.rootController popNavigationController]; + [self.rootController popRightNavigationController]; return nil; }else{ return [super popViewControllerAnimated:animated]; diff --git a/SASlideMenu/SASlideMenu/SASlideMenuPushSegue.m b/SASlideMenu/SASlideMenu/SASlideMenuPushSegue.m index a9f377b..d080960 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuPushSegue.m +++ b/SASlideMenu/SASlideMenu/SASlideMenuPushSegue.m @@ -18,7 +18,7 @@ -(void) perform{ SASlideMenuRootViewController* root = source.rootController; SASlideMenuNavigationController* destination = self.destinationViewController; - [root pushNavigationController:destination]; + [root pushRightNavigationController:destination]; } @end diff --git a/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.h b/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.h index c72b59c..cf20229 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.h +++ b/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.h @@ -11,7 +11,7 @@ @class SASlideMenuNavigationController; @class SASlideMenuViewController; -@interface SASlideMenuRootViewController : UIViewController +@interface SASlideMenuRootViewController : UIViewController @property (strong, nonatomic) SASlideMenuViewController* leftMenu; @@ -21,8 +21,11 @@ -(void) switchToContentViewController:(UINavigationController*) content; -(void) addContentViewController:(UIViewController*) content withIndexPath:(NSIndexPath*)indexPath; --(void) popNavigationController; --(void) pushNavigationController:(SASlideMenuNavigationController*)navigationController; + +-(void) popRightNavigationController; +-(void) pushRightNavigationController:(SASlideMenuNavigationController*)navigationController; + +-(UINavigationController*) controllerForIndexPath:(NSIndexPath*) indexPath; -(void) doSlideToSide; -(void) rightMenuAction; diff --git a/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.m b/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.m index bc888d3..6a175ef 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.m +++ b/SASlideMenu/SASlideMenu/SASlideMenuRootViewController.m @@ -113,7 +113,7 @@ -(void) doSlideToSide{ } [UIView animateWithDuration:kSlideInInterval delay:0.0 - options:UIViewAnimationCurveEaseInOut + options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self slideToSide:self.selectedContent]; } @@ -133,7 +133,7 @@ -(void) doSlideToLeftSide{ [UIView animateWithDuration:kSlideInInterval delay:0.0 - options:UIViewAnimationCurveEaseInOut + options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self slideToLeftSide:self.selectedContent]; } @@ -150,7 +150,7 @@ -(void) doSlideOut:(void (^)(BOOL completed))completion{ if ([self.leftMenu.slideMenuDelegate respondsToSelector:@selector(slideMenuWillSlideOut)]){ [self.leftMenu.slideMenuDelegate slideMenuWillSlideOut]; } - [UIView animateWithDuration:kSlideOutInterval delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ + [UIView animateWithDuration:kSlideOutInterval delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self slideOut:self.selectedContent]; } completion:^(BOOL finished) { if (completion) { @@ -167,7 +167,7 @@ -(void) doSlideIn:(void (^)(BOOL completed))completion{ if ([self.leftMenu.slideMenuDelegate respondsToSelector:@selector(slideMenuWillSlideIn)]){ [self.leftMenu.slideMenuDelegate slideMenuWillSlideIn]; } - [UIView animateWithDuration:kSlideInInterval delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ + [UIView animateWithDuration:kSlideInInterval delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self slideIn:self.selectedContent]; } completion:^(BOOL finished) { if (completion) { @@ -278,6 +278,10 @@ -(void) panItem:(UIPanGestureRecognizer*)gesture{ } } +-(UINavigationController*) controllerForIndexPath:(NSIndexPath*) indexPath{ + return [controllers objectForKey:indexPath]; +} + -(void) switchToContentViewController:(UINavigationController*) content{ CGRect bounds = self.view.bounds; self.view.userInteractionEnabled = NO; @@ -289,9 +293,10 @@ -(void) switchToContentViewController:(UINavigationController*) content{ if ([self.leftMenu.slideMenuDataSource respondsToSelector:@selector(slideOutThenIn)]){ slideOutThenIn = [self.leftMenu.slideMenuDataSource slideOutThenIn]; } - if (state != SASlideMenuStateInitial) { + BOOL hideContentOnStartup = ![self.leftMenu.slideMenuDataSource respondsToSelector:@selector(selectedIndexPath)]; + + if (state != SASlideMenuStateInitial || hideContentOnStartup) { if (slideOutThenIn) { - //Animate out the currently selected UIViewController [self doSlideOut:^(BOOL completed) { [self.selectedContent willMoveToParentViewController:nil]; [self.selectedContent.view removeFromSuperview]; @@ -359,7 +364,7 @@ -(void) addContentViewController:(UIViewController*) content withIndexPath:(NSIn } } --(void) pushNavigationController:(SASlideMenuNavigationController*)navigationController{ +-(void) pushRightNavigationController:(SASlideMenuNavigationController*)navigationController{ SASlideMenuRootViewController* root = self; root.navigationController = navigationController; navigationController.rootController = root; @@ -382,7 +387,8 @@ -(void) pushNavigationController:(SASlideMenuNavigationController*)navigationCon }]; } --(void) popNavigationController{ + +-(void) popRightNavigationController{ CGRect bounds = self.view.bounds; [self.navigationController willMoveToParentViewController:nil]; [UIView animateWithDuration:kSlideOutInterval animations:^{ @@ -417,20 +423,17 @@ -(void) viewDidLoad{ UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapShield:)]; [self.shieldWithMenu addGestureRecognizer:tapGesture]; - [tapGesture setDelegate:self]; UIPanGestureRecognizer* panGestureMenu = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panItem:)]; [panGestureMenu setMaximumNumberOfTouches:2]; - [panGestureMenu setDelegate:self]; [self.shieldWithMenu addGestureRecognizer:panGestureMenu]; UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panItem:)]; [panGesture setMaximumNumberOfTouches:2]; - [panGesture setDelegate:self]; [self.shield addGestureRecognizer:panGesture]; [self performSegueWithIdentifier:@"leftMenu" sender:self]; self.isRightMenuEnabled = NO; - if ([self.leftMenu.slideMenuDataSource respondsToSelector:@selector(hasRightMenuForSegueId:)]) { + if ([self.leftMenu.slideMenuDataSource respondsToSelector:@selector(hasRightMenuForIndexPath:)]) { [self performSegueWithIdentifier:@"rightMenu" sender:self]; } } diff --git a/SASlideMenu/SASlideMenu/SASlideMenuViewController.h b/SASlideMenu/SASlideMenu/SASlideMenuViewController.h index d0bc74f..291b11f 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuViewController.h +++ b/SASlideMenu/SASlideMenu/SASlideMenuViewController.h @@ -12,11 +12,12 @@ @class SASlideMenuRootViewController; -@interface SASlideMenuViewController : UITableViewController +@interface SASlideMenuViewController : UITableViewController @property(nonatomic,strong) SASlideMenuRootViewController* rootController; @property (assign, nonatomic) NSObject* slideMenuDataSource; @property (assign, nonatomic) NSObject* slideMenuDelegate; +-(void)selectContentAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITableViewScrollPosition)scrollPosition; @end diff --git a/SASlideMenu/SASlideMenu/SASlideMenuViewController.m b/SASlideMenu/SASlideMenu/SASlideMenuViewController.m index f2b0d7b..9fbb426 100644 --- a/SASlideMenu/SASlideMenu/SASlideMenuViewController.m +++ b/SASlideMenu/SASlideMenu/SASlideMenuViewController.m @@ -7,18 +7,57 @@ // #import "SASlideMenuViewController.h" - +#import "SASlideMenuRootViewController.h" @interface SASlideMenuViewController () @end @implementation SASlideMenuViewController +#pragma mark - +#pragma mark SASlideMenuViewController + +-(void)selectContentAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITableViewScrollPosition)scrollPosition{ + if ([self.slideMenuDataSource respondsToSelector:@selector(segueIdForIndexPath:)]) { + [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:scrollPosition]; + + if ([self.slideMenuDataSource respondsToSelector:@selector(allowContentViewControllerCachingForIndexPath:)] ) { + if ([self.slideMenuDataSource allowContentViewControllerCachingForIndexPath:indexPath]) { + + } + UINavigationController* controller = [self.rootController controllerForIndexPath:indexPath]; + if (controller) { + [self.rootController switchToContentViewController:controller]; + return; + } + } + NSString* segueId = [self.slideMenuDataSource segueIdForIndexPath:indexPath]; + [self performSegueWithIdentifier:segueId sender:self]; + } +} + +#pragma mark - +#pragma mark UIGestureRecognizerDelegate + +-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ + return YES; +} + #pragma mark - #pragma mark UITableViewDelegate -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if ([self.slideMenuDataSource respondsToSelector:@selector(segueIdForIndexPath:)]) { + if ([self.slideMenuDataSource respondsToSelector:@selector(allowContentViewControllerCachingForIndexPath:)] ) { + if ([self.slideMenuDataSource allowContentViewControllerCachingForIndexPath:indexPath]) { + + } + UINavigationController* controller = [self.rootController controllerForIndexPath:indexPath]; + if (controller) { + [self.rootController switchToContentViewController:controller]; + return; + } + } NSString* segueId = [self.slideMenuDataSource segueIdForIndexPath:indexPath]; [self performSegueWithIdentifier:segueId sender:self]; } diff --git a/SASlideMenuDynamic/en.lproj/MainStoryboard.storyboard b/SASlideMenuDynamic/en.lproj/MainStoryboard.storyboard index 437186e..c3c7f63 100644 --- a/SASlideMenuDynamic/en.lproj/MainStoryboard.storyboard +++ b/SASlideMenuDynamic/en.lproj/MainStoryboard.storyboard @@ -1,7 +1,7 @@ - + - + @@ -182,7 +182,7 @@ - + @@ -190,86 +190,133 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - + + - + @@ -320,7 +367,7 @@ - + @@ -385,84 +432,131 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + - - + + @@ -476,7 +570,7 @@ - + diff --git a/SASlideMenuStatic/LightViewController.h b/SASlideMenuStatic/LightViewController.h new file mode 100644 index 0000000..b2351cd --- /dev/null +++ b/SASlideMenuStatic/LightViewController.h @@ -0,0 +1,17 @@ +// +// LightViewController.h +// SASlideMenu +// +// Created by Stefano Antonelli on 2/18/13. +// Copyright (c) 2013 Stefano Antonelli. All rights reserved. +// + +#import +#import "SASlideMenuRootViewController.h" + +@interface LightViewController : UIViewController + +@property (nonatomic,strong) SASlideMenuViewController* menuViewController; + +-(IBAction)tap:(id)sender; +@end diff --git a/SASlideMenuStatic/LightViewController.m b/SASlideMenuStatic/LightViewController.m new file mode 100644 index 0000000..8e8409c --- /dev/null +++ b/SASlideMenuStatic/LightViewController.m @@ -0,0 +1,20 @@ +// +// LightViewController.m +// SASlideMenu +// +// Created by Stefano Antonelli on 2/18/13. +// Copyright (c) 2013 Stefano Antonelli. All rights reserved. +// + +#import "LightViewController.h" + +@interface LightViewController () + +@end + +@implementation LightViewController + +-(IBAction)tap:(id)sender{ + [self.menuViewController selectContentAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] scrollPosition:UITableViewScrollPositionTop]; +} +@end diff --git a/SASlideMenuStatic/en.lproj/MainStoryboard.storyboard b/SASlideMenuStatic/en.lproj/MainStoryboard.storyboard index 6774b7e..f771cdb 100644 --- a/SASlideMenuStatic/en.lproj/MainStoryboard.storyboard +++ b/SASlideMenuStatic/en.lproj/MainStoryboard.storyboard @@ -1,7 +1,7 @@ - + - + @@ -19,7 +19,7 @@ - + @@ -65,7 +65,6 @@ - @@ -101,7 +100,6 @@ - @@ -137,7 +135,6 @@ - @@ -149,10 +146,15 @@ + + + + + - + @@ -227,7 +229,7 @@ - + @@ -243,22 +245,39 @@ - + - + - + + + + - + @@ -305,7 +324,7 @@ - + @@ -324,6 +343,12 @@ + + + + + +