From ea8788878113c48ae780353a668c4162f4a5c67d Mon Sep 17 00:00:00 2001 From: Grigory Lutkov Date: Fri, 6 Nov 2015 19:51:27 +0300 Subject: [PATCH] Fixed bug with status bar, now you can set animation speed, status bar style and animation for every menu. Updated demo projects. Closes #6 --- .../project.pbxproj | 59 +- .../LGSideMenuControllerDemo/AppDelegate.h | 9 +- .../LGSideMenuControllerDemo/AppDelegate.m | 3 - .../Base.lproj/Main.storyboard | 134 ++- .../Choose.storyboard | 63 ++ .../ChooseNavigationController.h | 13 + .../ChooseNavigationController.m | 42 + .../LGSideMenuControllerDemo/Info.plist | 4 +- .../LGSideMenuControllerDemo/LeftViewCell.h | 2 +- .../LGSideMenuControllerDemo/LeftViewCell.m | 11 +- .../LeftViewController.m | 48 +- .../MainViewController.h | 3 + .../MainViewController.m | 269 +++--- .../NavigationController.h | 13 + .../NavigationController.m | 42 + .../LGSideMenuControllerDemo/RightViewCell.h | 2 +- .../LGSideMenuControllerDemo/RightViewCell.m | 11 +- .../RightViewController.m | 49 +- .../TableViewController.h | 13 + .../TableViewController.m | 96 +++ .../LGSideMenuControllerDemo/ViewController.m | 97 +-- Demo Storyboard/Podfile.lock | 4 +- .../project.pbxproj | 53 +- Demo/LGSideMenuControllerDemo/AppDelegate.h | 10 +- Demo/LGSideMenuControllerDemo/AppDelegate.m | 19 +- .../ChooseNavigationController.h | 13 + .../ChooseNavigationController.m | 47 ++ Demo/LGSideMenuControllerDemo/Info.plist | 2 +- .../LeftViewController.m | 39 +- .../MainViewController.h | 4 + .../MainViewController.m | 268 +++--- .../NavigationController.h | 13 + .../NavigationController.m | 45 + .../RightViewController.m | 40 +- .../TableViewController.h | 13 + .../TableViewController.m | 126 +++ .../LGSideMenuControllerDemo/ViewController.m | 67 +- Demo/Podfile.lock | 4 +- LGSideMenuController.podspec | 2 +- LGSideMenuController/LGSideMenuController.h | 40 +- LGSideMenuController/LGSideMenuController.m | 775 ++++++++++-------- 41 files changed, 1619 insertions(+), 948 deletions(-) create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/Choose.storyboard create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.h create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.m create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/NavigationController.h create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/NavigationController.m create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/TableViewController.h create mode 100644 Demo Storyboard/LGSideMenuControllerDemo/TableViewController.m create mode 100644 Demo/LGSideMenuControllerDemo/ChooseNavigationController.h create mode 100644 Demo/LGSideMenuControllerDemo/ChooseNavigationController.m create mode 100644 Demo/LGSideMenuControllerDemo/NavigationController.h create mode 100644 Demo/LGSideMenuControllerDemo/NavigationController.m create mode 100644 Demo/LGSideMenuControllerDemo/TableViewController.h create mode 100644 Demo/LGSideMenuControllerDemo/TableViewController.m diff --git a/Demo Storyboard/LGSideMenuControllerDemo.xcodeproj/project.pbxproj b/Demo Storyboard/LGSideMenuControllerDemo.xcodeproj/project.pbxproj index dbaf309..8993a20 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo.xcodeproj/project.pbxproj +++ b/Demo Storyboard/LGSideMenuControllerDemo.xcodeproj/project.pbxproj @@ -7,7 +7,11 @@ objects = { /* Begin PBXBuildFile section */ - 4A1CCB751BDBF74500709E2A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A1CCB741BDBF74500709E2A /* LaunchScreen.storyboard */; settings = {ASSET_TAGS = (); }; }; + 4A19DA581BECFE610072427E /* ChooseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A19DA551BECFE610072427E /* ChooseNavigationController.m */; }; + 4A19DA591BECFE610072427E /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A19DA571BECFE610072427E /* TableViewController.m */; }; + 4A19DA5C1BECFE900072427E /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A19DA5B1BECFE900072427E /* NavigationController.m */; }; + 4A19DA5E1BECFEAF0072427E /* Choose.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A19DA5D1BECFEAF0072427E /* Choose.storyboard */; }; + 4A1CCB751BDBF74500709E2A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A1CCB741BDBF74500709E2A /* LaunchScreen.storyboard */; }; 4A4243A11B6808E4008432A9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A4243A01B6808E4008432A9 /* main.m */; }; 4A4243A41B6808E4008432A9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A4243A31B6808E4008432A9 /* AppDelegate.m */; }; 4A4243A71B6808E4008432A9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A4243A61B6808E4008432A9 /* ViewController.m */; }; @@ -26,6 +30,13 @@ /* Begin PBXFileReference section */ 1D786D515F2DB6D9D388116A /* Pods-LGSideMenuControllerDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGSideMenuControllerDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LGSideMenuControllerDemo/Pods-LGSideMenuControllerDemo.release.xcconfig"; sourceTree = ""; }; + 4A19DA541BECFE610072427E /* ChooseNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChooseNavigationController.h; sourceTree = ""; }; + 4A19DA551BECFE610072427E /* ChooseNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChooseNavigationController.m; sourceTree = ""; }; + 4A19DA561BECFE610072427E /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = ""; }; + 4A19DA571BECFE610072427E /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = ""; }; + 4A19DA5A1BECFE900072427E /* NavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = ""; }; + 4A19DA5B1BECFE900072427E /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; + 4A19DA5D1BECFEAF0072427E /* Choose.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Choose.storyboard; sourceTree = ""; }; 4A1CCB741BDBF74500709E2A /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 4A42439B1B6808E4008432A9 /* LGSideMenuControllerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LGSideMenuControllerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4A42439F1B6808E4008432A9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -74,6 +85,34 @@ name = Pods; sourceTree = ""; }; + 4A19DA521BECFE2A0072427E /* Choose View Controller */ = { + isa = PBXGroup; + children = ( + 4A19DA541BECFE610072427E /* ChooseNavigationController.h */, + 4A19DA551BECFE610072427E /* ChooseNavigationController.m */, + 4A19DA561BECFE610072427E /* TableViewController.h */, + 4A19DA571BECFE610072427E /* TableViewController.m */, + 4A19DA5D1BECFEAF0072427E /* Choose.storyboard */, + ); + name = "Choose View Controller"; + sourceTree = ""; + }; + 4A19DA531BECFE360072427E /* Side Menu Controller */ = { + isa = PBXGroup; + children = ( + 4ADAFC471B691E0F00B33211 /* Right View Controller */, + 4ADAFC481B691E1300B33211 /* Left View Controller */, + 4A19DA5A1BECFE900072427E /* NavigationController.h */, + 4A19DA5B1BECFE900072427E /* NavigationController.m */, + 4ADAFC381B69190900B33211 /* MainViewController.h */, + 4ADAFC391B69190900B33211 /* MainViewController.m */, + 4A4243A51B6808E4008432A9 /* ViewController.h */, + 4A4243A61B6808E4008432A9 /* ViewController.m */, + 4A4243A81B6808E4008432A9 /* Main.storyboard */, + ); + name = "Side Menu Controller"; + sourceTree = ""; + }; 4A4243921B6808E4008432A9 = { isa = PBXGroup; children = ( @@ -95,15 +134,10 @@ 4A42439D1B6808E4008432A9 /* LGSideMenuControllerDemo */ = { isa = PBXGroup; children = ( - 4ADAFC471B691E0F00B33211 /* Right View Controller */, - 4ADAFC481B691E1300B33211 /* Left View Controller */, 4A4243A21B6808E4008432A9 /* AppDelegate.h */, 4A4243A31B6808E4008432A9 /* AppDelegate.m */, - 4A4243A51B6808E4008432A9 /* ViewController.h */, - 4A4243A61B6808E4008432A9 /* ViewController.m */, - 4ADAFC381B69190900B33211 /* MainViewController.h */, - 4ADAFC391B69190900B33211 /* MainViewController.m */, - 4A4243A81B6808E4008432A9 /* Main.storyboard */, + 4A19DA521BECFE2A0072427E /* Choose View Controller */, + 4A19DA531BECFE360072427E /* Side Menu Controller */, 4ADAFC311B6903F200B33211 /* Resources */, 4A4243AB1B6808E4008432A9 /* Images.xcassets */, 4A42439E1B6808E4008432A9 /* Supporting Files */, @@ -190,7 +224,7 @@ 4A4243931B6808E4008432A9 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0640; + LastUpgradeCheck = 0710; ORGANIZATIONNAME = "Grigory Lutkov"; TargetAttributes = { 4A42439A1B6808E4008432A9 = { @@ -224,6 +258,7 @@ 4ADAFC351B6903FF00B33211 /* image.png in Resources */, 4ADAFC371B6903FF00B33211 /* image3.png in Resources */, 4A4243AA1B6808E4008432A9 /* Main.storyboard in Resources */, + 4A19DA5E1BECFEAF0072427E /* Choose.storyboard in Resources */, 4A1CCB751BDBF74500709E2A /* LaunchScreen.storyboard in Resources */, 4ADAFC361B6903FF00B33211 /* image2.png in Resources */, 4A4243AC1B6808E4008432A9 /* Images.xcassets in Resources */, @@ -288,9 +323,12 @@ 4A4243A71B6808E4008432A9 /* ViewController.m in Sources */, 4A4243A41B6808E4008432A9 /* AppDelegate.m in Sources */, 4A4243A11B6808E4008432A9 /* main.m in Sources */, + 4A19DA591BECFE610072427E /* TableViewController.m in Sources */, 4ADAFC441B691DA500B33211 /* LeftViewController.m in Sources */, + 4A19DA581BECFE610072427E /* ChooseNavigationController.m in Sources */, 4ADAFC451B691DA500B33211 /* RightViewCell.m in Sources */, 4ADAFC461B691DA500B33211 /* RightViewController.m in Sources */, + 4A19DA5C1BECFE900072427E /* NavigationController.m in Sources */, 4ADAFC431B691DA500B33211 /* LeftViewCell.m in Sources */, 4ADAFC3A1B69190900B33211 /* MainViewController.m in Sources */, ); @@ -331,6 +369,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -400,6 +439,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = LGSideMenuControllerDemo/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -412,6 +452,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = LGSideMenuControllerDemo/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.h b/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.h index 0fa853c..cdc7e03 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.h +++ b/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.h @@ -8,16 +8,11 @@ #import -#warning CHOOSE TYPE 1 .. 5 - -#define TYPE 1 - -#define kMainViewController (MainViewController *)[[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] rootViewController] -#define kNavigationController (UINavigationController *)[(MainViewController *)[[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] rootViewController] rootViewController] +#define kMainViewController (MainViewController *)[UIApplication sharedApplication].delegate.window.rootViewController +#define kNavigationController (NavigationController *)[(MainViewController *)[UIApplication sharedApplication].delegate.window.rootViewController rootViewController] @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; @end - diff --git a/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.m b/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.m index 8874d91..8e89254 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/AppDelegate.m @@ -16,9 +16,6 @@ @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - if ([UIDevice currentDevice].systemVersion.floatValue < 7.0) - application.statusBarStyle = UIStatusBarStyleBlackOpaque; - return YES; } diff --git a/Demo Storyboard/LGSideMenuControllerDemo/Base.lproj/Main.storyboard b/Demo Storyboard/LGSideMenuControllerDemo/Base.lproj/Main.storyboard index f6ab0fa..32f5553 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/Base.lproj/Main.storyboard +++ b/Demo Storyboard/LGSideMenuControllerDemo/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -13,6 +13,7 @@ + @@ -26,16 +27,39 @@ - + + - + + + + + + + + + + + + + + + + + + + + + + + @@ -43,6 +67,7 @@ + @@ -54,16 +79,39 @@ - + + - + + + + + + + + + + + + + + + + + + + + + + + @@ -71,6 +119,7 @@ + @@ -89,6 +138,7 @@ + @@ -98,10 +148,10 @@ - + - + @@ -109,32 +159,60 @@ + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + diff --git a/Demo Storyboard/LGSideMenuControllerDemo/Choose.storyboard b/Demo Storyboard/LGSideMenuControllerDemo/Choose.storyboard new file mode 100644 index 0000000..3d59c7d --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/Choose.storyboard @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.h b/Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.h new file mode 100644 index 0000000..b95969b --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.h @@ -0,0 +1,13 @@ +// +// ChooseNavigationController.h +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface ChooseNavigationController : UINavigationController + +@end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.m b/Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.m new file mode 100644 index 0000000..b53a521 --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/ChooseNavigationController.m @@ -0,0 +1,42 @@ +// +// ChooseNavigationController.m +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "ChooseNavigationController.h" + +@interface ChooseNavigationController () + +@end + +@implementation ChooseNavigationController + +- (void)viewDidLoad +{ + [super viewDidLoad]; +} + +- (BOOL)shouldAutorotate +{ + return YES; +} + +- (BOOL)prefersStatusBarHidden +{ + return (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleLightContent; +} + +- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation +{ + return UIStatusBarAnimationNone; +} + +@end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/Info.plist b/Demo Storyboard/LGSideMenuControllerDemo/Info.plist index ce4aa64..bed1b4a 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/Info.plist +++ b/Demo Storyboard/LGSideMenuControllerDemo/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.test.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -25,7 +25,7 @@ UILaunchStoryboardName LaunchScreen UIMainStoryboardFile - Main + Choose UIRequiredDeviceCapabilities armv7 diff --git a/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.h b/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.h index f2c3943..f99175a 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.h +++ b/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.h @@ -10,7 +10,7 @@ @interface LeftViewCell : UITableViewCell -@property (strong, nonatomic) UIView *separatorView; +@property (assign, nonatomic) IBOutlet UIView *separatorView; @property (strong, nonatomic) UIColor *tintColor; @end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.m b/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.m index 8765100..7275db8 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/LeftViewCell.m @@ -18,16 +18,11 @@ - (void)awakeFromNib { [super awakeFromNib]; - self.selectionStyle = UITableViewCellSelectionStyleNone; + // ----- self.backgroundColor = [UIColor clearColor]; self.textLabel.font = [UIFont boldSystemFontOfSize:16.f]; - - // ----- - - _separatorView = [UIView new]; - [self addSubview:_separatorView]; } - (void)layoutSubviews @@ -36,10 +31,6 @@ - (void)layoutSubviews self.textLabel.textColor = _tintColor; _separatorView.backgroundColor = [_tintColor colorWithAlphaComponent:0.4]; - - CGFloat height = ([UIScreen mainScreen].scale == 1.f ? 1.f : 0.5); - - _separatorView.frame = CGRectMake(0.f, self.frame.size.height-height, self.frame.size.width*0.9, height); } - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated diff --git a/Demo Storyboard/LGSideMenuControllerDemo/LeftViewController.m b/Demo Storyboard/LGSideMenuControllerDemo/LeftViewController.m index bc6e93e..094afec 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/LeftViewController.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/LeftViewController.m @@ -7,10 +7,11 @@ // #import "LeftViewController.h" -#import "MainViewController.h" #import "AppDelegate.h" #import "LeftViewCell.h" #import "ViewController.h" +#import "MainViewController.h" +#import "NavigationController.h" @interface LeftViewController () @@ -20,12 +21,13 @@ @interface LeftViewController () @implementation LeftViewController -- (void)awakeFromNib +- (void)viewDidLoad { - [super awakeFromNib]; + [super viewDidLoad]; - _titlesArray = @[@"Set View Controllers", - @"Open Right View", + // ----- + + _titlesArray = @[@"Open Right View", @"", @"Profile", @"News", @@ -33,21 +35,9 @@ - (void)awakeFromNib @"Video", @"Music"]; - self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; - self.tableView.contentInset = UIEdgeInsetsMake(20.f, 0.f, 20.f, 0.f); - self.tableView.showsVerticalScrollIndicator = NO; -} - -#pragma mark - + // ----- -- (void)openLeftView -{ - [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; -} - -- (void)openRightView -{ - [kMainViewController showRightViewAnimated:YES completionHandler:nil]; + self.tableView.contentInset = UIEdgeInsetsMake(44.f, 0.f, 44.f, 0.f); } #pragma mark - UITableView DataSource @@ -69,8 +59,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N LeftViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.textLabel.text = _titlesArray[indexPath.row]; - cell.separatorView.hidden = !(indexPath.row != _titlesArray.count-1 && indexPath.row != 1 && indexPath.row != 2); - cell.userInteractionEnabled = (indexPath.row != 2); + cell.separatorView.hidden = !(indexPath.row != 0 && indexPath.row != 1 && indexPath.row != _titlesArray.count-1); + cell.userInteractionEnabled = (indexPath.row != 1); cell.tintColor = _tintColor; @@ -79,24 +69,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.row == 2) return 22.f; + if (indexPath.row == 1) return 22.f; else return 44.f; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) - { - ViewController *viewController = [kNavigationController viewControllers].firstObject; - - UIViewController *viewController2 = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; - viewController2.title = @"Test"; - - [kNavigationController setViewControllers:@[viewController, viewController2]]; - - [kMainViewController hideLeftViewAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 1) { if (![kMainViewController isLeftViewAlwaysVisible]) { @@ -109,7 +88,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath } else { - UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; + UIViewController *viewController = [UIViewController new]; + viewController.view.backgroundColor = [UIColor whiteColor]; viewController.title = _titlesArray[indexPath.row]; [kNavigationController pushViewController:viewController animated:YES]; diff --git a/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.h b/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.h index a94c560..365cf12 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.h +++ b/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.h @@ -10,4 +10,7 @@ @interface MainViewController : LGSideMenuController +- (void)setupWithPresentationStyle:(LGSideMenuPresentationStyle)style + type:(NSUInteger)type; + @end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.m b/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.m index c23441d..4c07d7e 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/MainViewController.m @@ -16,226 +16,249 @@ @interface MainViewController () @property (strong, nonatomic) LeftViewController *leftViewController; @property (strong, nonatomic) RightViewController *rightViewController; +@property (assign, nonatomic) NSUInteger type; @end @implementation MainViewController -- (void)awakeFromNib +- (void)setupWithPresentationStyle:(LGSideMenuPresentationStyle)style + type:(NSUInteger)type { - [super awakeFromNib]; - - self.view.backgroundColor = [UIColor whiteColor]; - - self.rootViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NavigationController"]; _leftViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"]; _rightViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"]; // ----- - if (TYPE == 1) + if (type == 0) { [self setLeftViewEnabledWithWidth:250.f - presentationStyle:LGSideMenuPresentationStyleScaleFromBig - alwaysVisibleOptions:0]; + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; - self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; // ----- [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleScaleFromBig - alwaysVisibleOptions:0]; + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; - self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; // ----- - _leftViewController.tableView.backgroundColor = [UIColor clearColor]; - _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; + if (style == LGSideMenuPresentationStyleScaleFromBig) + { + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - // ----- + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; - _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor whiteColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; - } - else if (TYPE == 2) - { - [self setLeftViewEnabledWithWidth:250.f - presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:0]; + // ----- - self.leftViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; - // ----- + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor whiteColor]; + } + else if (style == LGSideMenuPresentationStyleSlideAbove) + { + self.leftViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; - [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:0]; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor blackColor]; - self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + // ----- - // ----- + self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; - _leftViewController.tableView.backgroundColor = [UIColor clearColor]; - _leftViewController.tintColor = [UIColor blackColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor blackColor]; + } + else if (style == LGSideMenuPresentationStyleSlideBelow) + { + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - // ----- + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; - _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor blackColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; - } - else if (TYPE == 3) - { - [self setLeftViewEnabledWithWidth:250.f - presentationStyle:LGSideMenuPresentationStyleSlideBelow - alwaysVisibleOptions:0]; + // ----- - self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; + self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; - // ----- + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor whiteColor]; + } + else if (style == LGSideMenuPresentationStyleScaleFromLittle) + { + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleSlideBelow - alwaysVisibleOptions:0]; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; - self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; + // ----- - // ----- + self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; + + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor whiteColor]; + } + } + else if (type == 1) + { + [self setLeftViewEnabledWithWidth:250.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPhoneLandscape|LGSideMenuAlwaysVisibleOnPadLandscape]; + + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuAlwaysVisibleOnPadLandscape; + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; _leftViewController.tableView.backgroundColor = [UIColor clearColor]; _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; // ----- + [self setRightViewEnabledWithWidth:100.f + presentationStyle:LGSideMenuPresentationStyleSlideAbove + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuAlwaysVisibleOnPadLandscape; + self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor whiteColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; + _rightViewController.tintColor = [UIColor blackColor]; } - else if (TYPE == 4) + else if (type == 2) { - [self setLeftViewEnabledWithWidth:200.f - presentationStyle:LGSideMenuPresentationStyleScaleFromLittle - alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPadLandscape|LGSideMenuAlwaysVisibleOnPhoneLandscape]; + [self setLeftViewEnabledWithWidth:250.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; - self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; + self.leftViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor blackColor]; // ----- [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:0]; + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; - self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; - // ----- + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor blackColor]; + } + else if (type == 3) + { + [self setLeftViewEnabledWithWidth:250.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + + self.leftViewStatusBarStyle = UIStatusBarStyleLightContent; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; + self.leftViewBackgroundColor = [UIColor colorWithWhite:0.f alpha:0.5]; _leftViewController.tableView.backgroundColor = [UIColor clearColor]; _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; // ----- + [self setRightViewEnabledWithWidth:100.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + + self.rightViewStatusBarStyle = UIStatusBarStyleLightContent; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; + self.rightViewBackgroundColor = [UIColor colorWithWhite:0.f alpha:0.5]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor blackColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; + _rightViewController.tintColor = [UIColor whiteColor]; } - else if (TYPE == 5) + else if (type == 4) { - [self setLeftViewEnabledWithWidth:200.f + self.swipeGestureArea = LGSideMenuSwipeGestureAreaFull; + self.rootViewCoverColorForLeftView = [UIColor colorWithRed:0.f green:1.f blue:0.5 alpha:0.3]; + self.rootViewScaleForLeftView = 0.6; + self.rootViewLayerBorderWidth = 3.f; + self.rootViewLayerBorderColor = [UIColor whiteColor]; + self.rootViewLayerShadowRadius = 10.f; + self.rootViewCoverColorForRightView = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:0.3]; + + // ----- + + [self setLeftViewEnabledWithWidth:250.f presentationStyle:LGSideMenuPresentationStyleScaleFromBig - alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPadLandscape|LGSideMenuAlwaysVisibleOnPhoneLandscape]; + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + self.leftViewAnimationSpeed = 0.4; + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; self.leftViewBackgroundImageInitialScale = 1.5; self.leftViewInititialOffsetX = -200.f; self.leftViewInititialScale = 1.5; - self.rootViewCoverColorForLeftView = [UIColor colorWithRed:0.f green:1.f blue:0.5 alpha:0.3]; - self.rootViewScaleForLeftView = 0.6; - self.rootViewLayerBorderWidth = 3.f; - self.rootViewLayerBorderColor = [UIColor whiteColor]; - self.rootViewLayerShadowRadius = 10.f; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; // ----- [self setRightViewEnabledWithWidth:100.f presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPadLandscape|LGSideMenuAlwaysVisibleOnPhoneLandscape]; + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + self.rightViewAnimationSpeed = 0.3; + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; self.rightViewLayerBorderWidth = 3.f; self.rightViewLayerBorderColor = [UIColor blackColor]; self.rightViewLayerShadowRadius = 10.f; - self.rootViewCoverColorForRightView = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:0.3]; - - // ----- - - _leftViewController.tableView.backgroundColor = [UIColor clearColor]; - _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; - - // ----- - _rightViewController.tableView.backgroundColor = [UIColor clearColor]; _rightViewController.tintColor = [UIColor blackColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; } + + // ----- + + [_leftViewController.tableView reloadData]; + [self.leftView addSubview:_leftViewController.tableView]; + + [_rightViewController.tableView reloadData]; + [self.rightView addSubview:_rightViewController.tableView]; } - (void)leftViewWillLayoutSubviewsWithSize:(CGSize)size { [super leftViewWillLayoutSubviewsWithSize:size]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && (TYPE == 4 || TYPE == 5)) - { - if (self.isLeftViewAlwaysVisible) - { - _leftViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); - _leftViewController.tableView.contentInset = UIEdgeInsetsMake(0.f, 0.f, 20.f, 0.f); - } - else - { - _leftViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); - _leftViewController.tableView.contentInset = UIEdgeInsetsMake(20.f, 0.f, 20.f, 0.f); - } - } - else _leftViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); + if (![UIApplication sharedApplication].isStatusBarHidden && (_type == 2 || _type == 3)) + _leftViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); + else + _leftViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); } - (void)rightViewWillLayoutSubviewsWithSize:(CGSize)size { [super rightViewWillLayoutSubviewsWithSize:size]; - - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && (TYPE == 4 || TYPE == 5)) - { - if (self.isLeftViewAlwaysVisible) - _rightViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); - else - _rightViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); - } - else _rightViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); + + if (![UIApplication sharedApplication].isStatusBarHidden && (_type == 2 || _type == 3)) + _rightViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); + else + _rightViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); } - @end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/NavigationController.h b/Demo Storyboard/LGSideMenuControllerDemo/NavigationController.h new file mode 100644 index 0000000..9e29502 --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/NavigationController.h @@ -0,0 +1,13 @@ +// +// NavigationController.h +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 06.11.15. +// Copyright © 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface NavigationController : UINavigationController + +@end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/NavigationController.m b/Demo Storyboard/LGSideMenuControllerDemo/NavigationController.m new file mode 100644 index 0000000..eca9c68 --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/NavigationController.m @@ -0,0 +1,42 @@ +// +// NavigationController.m +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 06.11.15. +// Copyright © 2015 Grigory Lutkov. All rights reserved. +// + +#import "NavigationController.h" + +@interface NavigationController () + +@end + +@implementation NavigationController + +- (void)viewDidLoad +{ + [super viewDidLoad]; +} + +- (BOOL)shouldAutorotate +{ + return YES; +} + +- (BOOL)prefersStatusBarHidden +{ + return (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} + +- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation +{ + return UIStatusBarAnimationNone; +} + +@end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.h b/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.h index 72f77ed..78c6068 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.h +++ b/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.h @@ -10,7 +10,7 @@ @interface RightViewCell : UITableViewCell -@property (strong, nonatomic) UIView *separatorView; +@property (assign, nonatomic) IBOutlet UIView *separatorView; @property (strong, nonatomic) UIColor *tintColor; @end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.m b/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.m index f96256a..2f61005 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/RightViewCell.m @@ -18,18 +18,13 @@ - (void)awakeFromNib { [super awakeFromNib]; - self.selectionStyle = UITableViewCellSelectionStyleNone; + // ----- self.backgroundColor = [UIColor clearColor]; self.textLabel.textAlignment = NSTextAlignmentCenter; self.textLabel.numberOfLines = 0; self.textLabel.lineBreakMode = NSLineBreakByWordWrapping; - - // ----- - - _separatorView = [UIView new]; - [self addSubview:_separatorView]; } - (void)layoutSubviews @@ -38,10 +33,6 @@ - (void)layoutSubviews self.textLabel.textColor = _tintColor; _separatorView.backgroundColor = [_tintColor colorWithAlphaComponent:0.4]; - - CGFloat height = ([UIScreen mainScreen].scale == 1.f ? 1.f : 0.5); - - _separatorView.frame = CGRectMake(self.frame.size.width*0.1, self.frame.size.height-height, self.frame.size.width*0.9, height); } - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated diff --git a/Demo Storyboard/LGSideMenuControllerDemo/RightViewController.m b/Demo Storyboard/LGSideMenuControllerDemo/RightViewController.m index 0fa4221..e0b507e 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/RightViewController.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/RightViewController.m @@ -7,10 +7,11 @@ // #import "RightViewController.h" -#import "MainViewController.h" #import "AppDelegate.h" #import "RightViewCell.h" #import "ViewController.h" +#import "MainViewController.h" +#import "NavigationController.h" @interface RightViewController () @@ -20,12 +21,13 @@ @interface RightViewController () @implementation RightViewController -- (void)awakeFromNib +- (void)viewDidLoad { - [super awakeFromNib]; + [super viewDidLoad]; - _titlesArray = @[@"Set VC", - @"Open Left View", + // ----- + + _titlesArray = @[@"Open Left View", @"", @"1", @"2", @@ -38,20 +40,9 @@ - (void)awakeFromNib @"9", @"10"]; - self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; - self.tableView.showsVerticalScrollIndicator = NO; -} - -#pragma mark - - -- (void)openLeftView -{ - [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; -} + // ----- -- (void)openRightView -{ - [kMainViewController showRightViewAnimated:YES completionHandler:nil]; + self.tableView.contentInset = UIEdgeInsetsMake(44.f, 0.f, 44.f, 0.f); } #pragma mark - UITableView DataSource @@ -73,12 +64,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N RightViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.textLabel.text = _titlesArray[indexPath.row]; - if (indexPath.row < 3) + if (indexPath.row == 0) cell.textLabel.font = [UIFont boldSystemFontOfSize:15.f]; else cell.textLabel.font = [UIFont boldSystemFontOfSize:30.f]; - cell.separatorView.hidden = !(indexPath.row != _titlesArray.count-1 && indexPath.row != 1 && indexPath.row != 2); - cell.userInteractionEnabled = (indexPath.row != 2); + cell.separatorView.hidden = !(indexPath.row != 0 && indexPath.row != 1 && indexPath.row != _titlesArray.count-1); + cell.userInteractionEnabled = (indexPath.row != 1); cell.tintColor = _tintColor; @@ -87,24 +78,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.row == 2) return 50.f; + if (indexPath.row == 1) return 50.f; else return 100.f; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) - { - ViewController *viewController = [kNavigationController viewControllers].firstObject; - - UIViewController *viewController2 = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; - viewController2.title = @"Test"; - - [kNavigationController setViewControllers:@[viewController, viewController2]]; - - [kMainViewController hideRightViewAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 1) { if (![kMainViewController isRightViewAlwaysVisible]) { @@ -117,7 +97,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath } else { - UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; + UIViewController *viewController = [UIViewController new]; + viewController.view.backgroundColor = [UIColor whiteColor]; viewController.title = [NSString stringWithFormat:@"Test %@", _titlesArray[indexPath.row]]; [kNavigationController pushViewController:viewController animated:YES]; diff --git a/Demo Storyboard/LGSideMenuControllerDemo/TableViewController.h b/Demo Storyboard/LGSideMenuControllerDemo/TableViewController.h new file mode 100644 index 0000000..61a10d8 --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/TableViewController.h @@ -0,0 +1,13 @@ +// +// TableViewController.h +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface TableViewController : UITableViewController + +@end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/TableViewController.m b/Demo Storyboard/LGSideMenuControllerDemo/TableViewController.m new file mode 100644 index 0000000..78ac50e --- /dev/null +++ b/Demo Storyboard/LGSideMenuControllerDemo/TableViewController.m @@ -0,0 +1,96 @@ +// +// TableViewController.m +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "TableViewController.h" +#import "MainViewController.h" +#import "NavigationController.h" +#import "ViewController.h" + +@interface TableViewController () + +@property (strong, nonatomic) NSArray *titlesArray; + +@end + +@implementation TableViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + _titlesArray = @[@"Style Scale From Big", + @"Style Slide Above", + @"Style Slide Below", + @"Style Scale From Little", + @"Landscape always visible", + @"Status bar always visible", + @"Status bar light content", + @"Custom style"]; +} + +#pragma mark - UITableView DataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _titlesArray.count; +} + +#pragma mark - UITableView Delegate + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; + cell.textLabel.text = _titlesArray[indexPath.row]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; + + UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"]; + MainViewController *mainViewController = [storyboard instantiateInitialViewController]; + mainViewController.rootViewController = navigationController; + + if (indexPath.row == 0) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleScaleFromBig type:0]; + else if (indexPath.row == 1) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideAbove type:0]; + else if (indexPath.row == 2) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideBelow type:0]; + else if (indexPath.row == 3) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleScaleFromLittle type:0]; + else if (indexPath.row == 4) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleScaleFromBig type:1]; + else if (indexPath.row == 5) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideAbove type:2]; + else if (indexPath.row == 6) + [mainViewController setupWithPresentationStyle:LGSideMenuPresentationStyleSlideAbove type:3]; + else if (indexPath.row == 7) + [mainViewController setupWithPresentationStyle:0 type:4]; + + UIWindow *window = [UIApplication sharedApplication].delegate.window; + + window.rootViewController = mainViewController; + + [UIView transitionWithView:window + duration:0.3 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:nil + completion:nil]; +} + +@end diff --git a/Demo Storyboard/LGSideMenuControllerDemo/ViewController.m b/Demo Storyboard/LGSideMenuControllerDemo/ViewController.m index f9e8fae..a2a625a 100644 --- a/Demo Storyboard/LGSideMenuControllerDemo/ViewController.m +++ b/Demo Storyboard/LGSideMenuControllerDemo/ViewController.m @@ -7,108 +7,49 @@ // #import "ViewController.h" -#import "MainViewController.h" #import "AppDelegate.h" +#import "ChooseNavigationController.h" +#import "TableViewController.h" +#import "MainViewController.h" @interface ViewController () -@property (strong, nonatomic) UIImageView *imageView; -@property (strong, nonatomic) UIButton *button; - @end @implementation ViewController -- (void)awakeFromNib +- (void)viewDidLoad { - self.title = @"LGSideMenuController"; - - self.view.backgroundColor = [UIColor whiteColor]; - - // ----- - - _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image3"]]; - _imageView.contentMode = UIViewContentModeScaleAspectFill; - [self.view addSubview:_imageView]; - - _button = [UIButton new]; - _button.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.5]; - [_button setTitle:@"Push View Controller" forState:UIControlStateNormal]; - [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; - [_button setTitleColor:[UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f] forState:UIControlStateHighlighted]; - [_button addTarget:self action:@selector(pushViewControllerAction) forControlEvents:UIControlEventTouchUpInside]; - [self.view addSubview:_button]; - - // ----- - - [self checkNavItemButtonsWithInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation]; -} - -- (void)viewWillLayoutSubviews -{ - [super viewWillLayoutSubviews]; - - _imageView.frame = CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height); - - _button.frame = CGRectMake(0.f, self.view.frame.size.height-44.f, self.view.frame.size.width, 44.f); + [super viewDidLoad]; } #pragma mark - -- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator +- (IBAction)openLeftView:(id)sender { - [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; - - UIInterfaceOrientation interfaceOrientation = (size.width < size.height ? UIInterfaceOrientationPortrait : UIInterfaceOrientationLandscapeLeft); - - [self checkNavItemButtonsWithInterfaceOrientation:interfaceOrientation]; + [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; } -- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration +- (IBAction)openRightView:(id)sender { - [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; - - [self checkNavItemButtonsWithInterfaceOrientation:toInterfaceOrientation]; + [kMainViewController showRightViewAnimated:YES completionHandler:nil]; } -- (void)checkNavItemButtonsWithInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +- (IBAction)showChooseController:(id)sender { - if (TYPE == 4 || TYPE == 5) - { - if ([kMainViewController isLeftViewAlwaysVisibleForInterfaceOrientation:interfaceOrientation]) - self.navigationItem.leftBarButtonItem = nil; - else - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(openLeftView)]; + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Choose" bundle:[NSBundle mainBundle]]; - if ([kMainViewController isRightViewAlwaysVisibleForInterfaceOrientation:interfaceOrientation]) - self.navigationItem.rightBarButtonItem = nil; - else - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(openRightView)]; - } - else - { - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(openLeftView)]; - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(openRightView)]; - } -} - -#pragma mark - + ChooseNavigationController *navigationController = [storyboard instantiateInitialViewController]; -- (void)openLeftView -{ - [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; -} + UIWindow *window = [UIApplication sharedApplication].delegate.window; -- (void)openRightView -{ - [kMainViewController showRightViewAnimated:YES completionHandler:nil]; -} + window.rootViewController = navigationController; -- (void)pushViewControllerAction -{ - UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; - viewController.title = @"Test"; - [kNavigationController pushViewController:viewController animated:YES]; + [UIView transitionWithView:window + duration:0.3 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:nil + completion:nil]; } @end diff --git a/Demo Storyboard/Podfile.lock b/Demo Storyboard/Podfile.lock index 87ff06d..96d7bb3 100644 --- a/Demo Storyboard/Podfile.lock +++ b/Demo Storyboard/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - LGSideMenuController (1.0.4) + - LGSideMenuController (1.0.5) DEPENDENCIES: - LGSideMenuController (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - LGSideMenuController: a9296cca27657824443b945323cfb49ea4254482 + LGSideMenuController: 0b3a8a9e33d5ae16fada970566e14dc5b413bafc COCOAPODS: 0.39.0 diff --git a/Demo/LGSideMenuControllerDemo.xcodeproj/project.pbxproj b/Demo/LGSideMenuControllerDemo.xcodeproj/project.pbxproj index e8a7447..e4ae398 100644 --- a/Demo/LGSideMenuControllerDemo.xcodeproj/project.pbxproj +++ b/Demo/LGSideMenuControllerDemo.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 1B02B5B256CAF8274A9895C1 /* libPods-LGSideMenuControllerDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F8C0B3D6B7FC45F42B6E52E2 /* libPods-LGSideMenuControllerDemo.a */; }; 4A339C431AFD3D6600F75B99 /* image2.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A339C421AFD3D6600F75B99 /* image2.png */; }; + 4A371ED81BEBA53000FB3DA4 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A371ED71BEBA53000FB3DA4 /* NavigationController.m */; }; + 4A371EDB1BEBA97D00FB3DA4 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A371EDA1BEBA97D00FB3DA4 /* TableViewController.m */; }; + 4A371EE31BEBB20D00FB3DA4 /* ChooseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A371EE21BEBB20D00FB3DA4 /* ChooseNavigationController.m */; }; 4A4319171AECF95D0088EFD7 /* LeftViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A4319161AECF95D0088EFD7 /* LeftViewController.m */; }; 4A43191A1AECFECB0088EFD7 /* LeftViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A4319191AECFECB0088EFD7 /* LeftViewCell.m */; }; 4A4319201AED009D0088EFD7 /* RightViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A43191D1AED009D0088EFD7 /* RightViewCell.m */; }; @@ -20,11 +23,17 @@ 4A645CDE1B02797300FFBDF6 /* image3.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A645CDD1B02797300FFBDF6 /* image3.png */; }; 4A66FCA01AEBC443005B8B0A /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A66FC9F1AEBC443005B8B0A /* MainViewController.m */; }; 4A6FE4F51AFBDBD2003887C9 /* image.png in Resources */ = {isa = PBXBuildFile; fileRef = 4A6FE4F41AFBDBD2003887C9 /* image.png */; }; - 4A8221CD1BDD321C00195454 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A8221CC1BDD321C00195454 /* LaunchScreen.storyboard */; settings = {ASSET_TAGS = (); }; }; + 4A8221CD1BDD321C00195454 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A8221CC1BDD321C00195454 /* LaunchScreen.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 4A339C421AFD3D6600F75B99 /* image2.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = image2.png; sourceTree = ""; }; + 4A371ED61BEBA53000FB3DA4 /* NavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationController.h; sourceTree = ""; }; + 4A371ED71BEBA53000FB3DA4 /* NavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NavigationController.m; sourceTree = ""; }; + 4A371ED91BEBA97C00FB3DA4 /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = ""; }; + 4A371EDA1BEBA97D00FB3DA4 /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = ""; }; + 4A371EE11BEBB20D00FB3DA4 /* ChooseNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChooseNavigationController.h; sourceTree = ""; }; + 4A371EE21BEBB20D00FB3DA4 /* ChooseNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChooseNavigationController.m; sourceTree = ""; }; 4A4319151AECF95D0088EFD7 /* LeftViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LeftViewController.h; sourceTree = ""; }; 4A4319161AECF95D0088EFD7 /* LeftViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LeftViewController.m; sourceTree = ""; }; 4A4319181AECFECB0088EFD7 /* LeftViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LeftViewCell.h; sourceTree = ""; }; @@ -63,6 +72,32 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 4A371EDF1BEBB19500FB3DA4 /* Choose View Controller */ = { + isa = PBXGroup; + children = ( + 4A371EE11BEBB20D00FB3DA4 /* ChooseNavigationController.h */, + 4A371EE21BEBB20D00FB3DA4 /* ChooseNavigationController.m */, + 4A371ED91BEBA97C00FB3DA4 /* TableViewController.h */, + 4A371EDA1BEBA97D00FB3DA4 /* TableViewController.m */, + ); + name = "Choose View Controller"; + sourceTree = ""; + }; + 4A371EE01BEBB1A400FB3DA4 /* Side Menu Controller */ = { + isa = PBXGroup; + children = ( + 4A43191B1AED007A0088EFD7 /* Right View Controller */, + 4A4319141AECF93A0088EFD7 /* Left View Controller */, + 4A371ED61BEBA53000FB3DA4 /* NavigationController.h */, + 4A371ED71BEBA53000FB3DA4 /* NavigationController.m */, + 4A66FC9E1AEBC443005B8B0A /* MainViewController.h */, + 4A66FC9F1AEBC443005B8B0A /* MainViewController.m */, + 4A5888E01AE94907004AFC57 /* ViewController.h */, + 4A5888E11AE94907004AFC57 /* ViewController.m */, + ); + name = "Side Menu Controller"; + sourceTree = ""; + }; 4A4319141AECF93A0088EFD7 /* Left View Controller */ = { isa = PBXGroup; children = ( @@ -106,14 +141,10 @@ 4A5888B71AE9489E004AFC57 /* LGSideMenuControllerDemo */ = { isa = PBXGroup; children = ( - 4A43191B1AED007A0088EFD7 /* Right View Controller */, - 4A4319141AECF93A0088EFD7 /* Left View Controller */, 4A5888BC1AE9489E004AFC57 /* AppDelegate.h */, 4A5888BD1AE9489E004AFC57 /* AppDelegate.m */, - 4A66FC9E1AEBC443005B8B0A /* MainViewController.h */, - 4A66FC9F1AEBC443005B8B0A /* MainViewController.m */, - 4A5888E01AE94907004AFC57 /* ViewController.h */, - 4A5888E11AE94907004AFC57 /* ViewController.m */, + 4A371EDF1BEBB19500FB3DA4 /* Choose View Controller */, + 4A371EE01BEBB1A400FB3DA4 /* Side Menu Controller */, 4A6FE4F31AFBDBC4003887C9 /* Resources */, 4A5888C51AE9489E004AFC57 /* Images.xcassets */, 4A5888B81AE9489E004AFC57 /* Supporting Files */, @@ -187,7 +218,7 @@ 4A5888AD1AE9489E004AFC57 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0630; + LastUpgradeCheck = 0710; ORGANIZATIONNAME = "Grigory Lutkov"; TargetAttributes = { 4A5888B41AE9489E004AFC57 = { @@ -281,12 +312,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4A371EDB1BEBA97D00FB3DA4 /* TableViewController.m in Sources */, 4A5888BE1AE9489E004AFC57 /* AppDelegate.m in Sources */, 4A43191A1AECFECB0088EFD7 /* LeftViewCell.m in Sources */, 4A4319171AECF95D0088EFD7 /* LeftViewController.m in Sources */, + 4A371EE31BEBB20D00FB3DA4 /* ChooseNavigationController.m in Sources */, 4A5888BB1AE9489E004AFC57 /* main.m in Sources */, 4A4319201AED009D0088EFD7 /* RightViewCell.m in Sources */, 4A4319211AED009D0088EFD7 /* RightViewController.m in Sources */, + 4A371ED81BEBA53000FB3DA4 /* NavigationController.m in Sources */, 4A66FCA01AEBC443005B8B0A /* MainViewController.m in Sources */, 4A5888E31AE94907004AFC57 /* ViewController.m in Sources */, ); @@ -316,6 +350,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -386,6 +421,7 @@ INFOPLIST_FILE = LGSideMenuControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 6.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -399,6 +435,7 @@ INFOPLIST_FILE = LGSideMenuControllerDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 6.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.test.$(PRODUCT_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/Demo/LGSideMenuControllerDemo/AppDelegate.h b/Demo/LGSideMenuControllerDemo/AppDelegate.h index d8035e9..d209b08 100644 --- a/Demo/LGSideMenuControllerDemo/AppDelegate.h +++ b/Demo/LGSideMenuControllerDemo/AppDelegate.h @@ -7,18 +7,12 @@ // #import -#import "MainViewController.h" -#warning CHOOSE TYPE 1 .. 5 - -#define TYPE 1 - -#define kMainViewController [(AppDelegate *)[[UIApplication sharedApplication] delegate] mainViewController] -#define kNavigationController (UINavigationController *)[[(AppDelegate *)[[UIApplication sharedApplication] delegate] mainViewController] rootViewController] +#define kMainViewController (MainViewController *)[UIApplication sharedApplication].delegate.window.rootViewController +#define kNavigationController (NavigationController *)[(MainViewController *)[UIApplication sharedApplication].delegate.window.rootViewController rootViewController] @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) MainViewController *mainViewController; @end diff --git a/Demo/LGSideMenuControllerDemo/AppDelegate.m b/Demo/LGSideMenuControllerDemo/AppDelegate.m index a93b98e..79b8fad 100644 --- a/Demo/LGSideMenuControllerDemo/AppDelegate.m +++ b/Demo/LGSideMenuControllerDemo/AppDelegate.m @@ -7,7 +7,8 @@ // #import "AppDelegate.h" -#import "ViewController.h" +#import "ChooseNavigationController.h" +#import "TableViewController.h" @implementation AppDelegate @@ -16,15 +17,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( if ([UIDevice currentDevice].systemVersion.floatValue < 7.0) application.statusBarStyle = UIStatusBarStyleBlackOpaque; - ViewController *viewController = [ViewController new]; - - UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; - - self.mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController]; + TableViewController *viewController = [TableViewController new]; + ChooseNavigationController *navigationController = [[ChooseNavigationController alloc] initWithRootViewController:viewController]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.rootViewController = self.mainViewController; self.window.backgroundColor = [UIColor whiteColor]; + self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES; @@ -57,11 +55,4 @@ - (void)applicationWillTerminate:(UIApplication *)application // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } -#pragma mark - - -- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation -{ - application.statusBarHidden = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && UIInterfaceOrientationIsLandscape(application.statusBarOrientation)); -} - @end diff --git a/Demo/LGSideMenuControllerDemo/ChooseNavigationController.h b/Demo/LGSideMenuControllerDemo/ChooseNavigationController.h new file mode 100644 index 0000000..b95969b --- /dev/null +++ b/Demo/LGSideMenuControllerDemo/ChooseNavigationController.h @@ -0,0 +1,13 @@ +// +// ChooseNavigationController.h +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface ChooseNavigationController : UINavigationController + +@end diff --git a/Demo/LGSideMenuControllerDemo/ChooseNavigationController.m b/Demo/LGSideMenuControllerDemo/ChooseNavigationController.m new file mode 100644 index 0000000..2605a4c --- /dev/null +++ b/Demo/LGSideMenuControllerDemo/ChooseNavigationController.m @@ -0,0 +1,47 @@ +// +// ChooseNavigationController.m +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "ChooseNavigationController.h" + +@interface ChooseNavigationController () + +@end + +@implementation ChooseNavigationController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.navigationBar.translucent = YES; + self.navigationBar.barTintColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f]; + self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]}; + self.navigationBar.tintColor = [UIColor colorWithWhite:1.f alpha:0.5]; +} + +- (BOOL)shouldAutorotate +{ + return YES; +} + +- (BOOL)prefersStatusBarHidden +{ + return (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleLightContent; +} + +- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation +{ + return UIStatusBarAnimationNone; +} + +@end diff --git a/Demo/LGSideMenuControllerDemo/Info.plist b/Demo/LGSideMenuControllerDemo/Info.plist index 5319340..c913168 100644 --- a/Demo/LGSideMenuControllerDemo/Info.plist +++ b/Demo/LGSideMenuControllerDemo/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.test.$(PRODUCT_NAME) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Demo/LGSideMenuControllerDemo/LeftViewController.m b/Demo/LGSideMenuControllerDemo/LeftViewController.m index c8ded75..f242721 100644 --- a/Demo/LGSideMenuControllerDemo/LeftViewController.m +++ b/Demo/LGSideMenuControllerDemo/LeftViewController.m @@ -10,6 +10,8 @@ #import "AppDelegate.h" #import "LeftViewCell.h" #import "ViewController.h" +#import "MainViewController.h" +#import "NavigationController.h" @interface LeftViewController () @@ -24,8 +26,7 @@ - (id)init self = [super initWithStyle:UITableViewStylePlain]; if (self) { - _titlesArray = @[@"Set View Controllers", - @"Open Right View", + _titlesArray = @[@"Open Right View", @"", @"Profile", @"News", @@ -35,24 +36,12 @@ - (id)init [self.tableView registerClass:[LeftViewCell class] forCellReuseIdentifier:@"cell"]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; - self.tableView.contentInset = UIEdgeInsetsMake(20.f, 0.f, 20.f, 0.f); + self.tableView.contentInset = UIEdgeInsetsMake(44.f, 0.f, 44.f, 0.f); self.tableView.showsVerticalScrollIndicator = NO; } return self; } -#pragma mark - - -- (void)openLeftView -{ - [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; -} - -- (void)openRightView -{ - [kMainViewController showRightViewAnimated:YES completionHandler:nil]; -} - #pragma mark - UITableView DataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -72,8 +61,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N LeftViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.textLabel.text = _titlesArray[indexPath.row]; - cell.separatorView.hidden = !(indexPath.row != _titlesArray.count-1 && indexPath.row != 1 && indexPath.row != 2); - cell.userInteractionEnabled = (indexPath.row != 2); + cell.separatorView.hidden = !(indexPath.row != 0 && indexPath.row != 1 && indexPath.row != _titlesArray.count-1); + cell.userInteractionEnabled = (indexPath.row != 1); cell.tintColor = _tintColor; @@ -82,7 +71,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.row == 2) return 22.f; + if (indexPath.row == 1) return 22.f; else return 44.f; } @@ -90,19 +79,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath { if (indexPath.row == 0) { - ViewController *viewController = [ViewController new]; - - UIViewController *viewController2 = [UIViewController new]; - viewController2.view.backgroundColor = [UIColor whiteColor]; - viewController2.title = @"Test"; - - [kNavigationController setViewControllers:@[viewController, viewController2]]; - - [kMainViewController hideLeftViewAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 1) - { - if (!kMainViewController.isLeftViewAlwaysVisible) + if (![kMainViewController isLeftViewAlwaysVisible]) { [kMainViewController hideLeftViewAnimated:YES completionHandler:^(void) { diff --git a/Demo/LGSideMenuControllerDemo/MainViewController.h b/Demo/LGSideMenuControllerDemo/MainViewController.h index a94c560..63ffd04 100644 --- a/Demo/LGSideMenuControllerDemo/MainViewController.h +++ b/Demo/LGSideMenuControllerDemo/MainViewController.h @@ -10,4 +10,8 @@ @interface MainViewController : LGSideMenuController +- (instancetype)initWithRootViewController:(UIViewController *)rootViewController + presentationStyle:(LGSideMenuPresentationStyle)style + type:(NSUInteger)type; + @end diff --git a/Demo/LGSideMenuControllerDemo/MainViewController.m b/Demo/LGSideMenuControllerDemo/MainViewController.m index 5a51fa5..ff1c172 100644 --- a/Demo/LGSideMenuControllerDemo/MainViewController.m +++ b/Demo/LGSideMenuControllerDemo/MainViewController.m @@ -16,191 +16,237 @@ @interface MainViewController () @property (strong, nonatomic) LeftViewController *leftViewController; @property (strong, nonatomic) RightViewController *rightViewController; +@property (assign, nonatomic) NSUInteger type; @end @implementation MainViewController -- (id)initWithRootViewController:(UIViewController *)rootViewController +- (instancetype)initWithRootViewController:(UIViewController *)rootViewController + presentationStyle:(LGSideMenuPresentationStyle)style + type:(NSUInteger)type { self = [super initWithRootViewController:rootViewController]; if (self) { - self.view.backgroundColor = [UIColor whiteColor]; + _type = type; + + // ----- _leftViewController = [LeftViewController new]; _rightViewController = [RightViewController new]; // ----- - if (TYPE == 1) + if (type == 0) { [self setLeftViewEnabledWithWidth:250.f - presentationStyle:LGSideMenuPresentationStyleScaleFromBig - alwaysVisibleOptions:0]; + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; - self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; // ----- [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleScaleFromBig - alwaysVisibleOptions:0]; + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; - self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; // ----- - _leftViewController.tableView.backgroundColor = [UIColor clearColor]; - _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; + if (style == LGSideMenuPresentationStyleScaleFromBig) + { + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - // ----- + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; - _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor whiteColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; - } - else if (TYPE == 2) - { - [self setLeftViewEnabledWithWidth:250.f - presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:0]; + // ----- - self.leftViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; - // ----- + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor whiteColor]; + } + else if (style == LGSideMenuPresentationStyleSlideAbove) + { + self.leftViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; - [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:0]; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor blackColor]; - self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + // ----- - // ----- + self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; - _leftViewController.tableView.backgroundColor = [UIColor clearColor]; - _leftViewController.tintColor = [UIColor blackColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor blackColor]; + } + else if (style == LGSideMenuPresentationStyleSlideBelow) + { + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - // ----- + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; - _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor blackColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; - } - else if (TYPE == 3) - { - [self setLeftViewEnabledWithWidth:250.f - presentationStyle:LGSideMenuPresentationStyleSlideBelow - alwaysVisibleOptions:0]; + // ----- - self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; + self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; - // ----- + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor whiteColor]; + } + else if (style == LGSideMenuPresentationStyleScaleFromLittle) + { + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleSlideBelow - alwaysVisibleOptions:0]; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; - self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; + // ----- - // ----- + self.rightViewBackgroundImage = [UIImage imageNamed:@"image2"]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor whiteColor]; + } + } + else if (type == 1) + { + [self setLeftViewEnabledWithWidth:250.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPhoneLandscape|LGSideMenuAlwaysVisibleOnPadLandscape]; + + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuAlwaysVisibleOnPadLandscape; + self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; - + // ----- + [self setRightViewEnabledWithWidth:100.f + presentationStyle:LGSideMenuPresentationStyleSlideAbove + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuAlwaysVisibleOnPadLandscape; + self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor whiteColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; + _rightViewController.tintColor = [UIColor blackColor]; } - else if (TYPE == 4) + else if (type == 2) { - [self setLeftViewEnabledWithWidth:200.f - presentationStyle:LGSideMenuPresentationStyleScaleFromLittle - alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPadLandscape|LGSideMenuAlwaysVisibleOnPhoneLandscape]; + [self setLeftViewEnabledWithWidth:250.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; - self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; - self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; + self.leftViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; + + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor blackColor]; // ----- [self setRightViewEnabledWithWidth:100.f - presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:0]; + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.9]; - self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; - // ----- + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; + _rightViewController.tintColor = [UIColor blackColor]; + } + else if (type == 3) + { + [self setLeftViewEnabledWithWidth:250.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + + self.leftViewStatusBarStyle = UIStatusBarStyleLightContent; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; + self.leftViewBackgroundColor = [UIColor colorWithWhite:0.f alpha:0.5]; _leftViewController.tableView.backgroundColor = [UIColor clearColor]; _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; // ----- + [self setRightViewEnabledWithWidth:100.f + presentationStyle:style + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + + self.rightViewStatusBarStyle = UIStatusBarStyleLightContent; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnAll; + self.rightViewBackgroundColor = [UIColor colorWithWhite:0.f alpha:0.5]; + _rightViewController.tableView.backgroundColor = [UIColor clearColor]; - _rightViewController.tintColor = [UIColor blackColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; + _rightViewController.tintColor = [UIColor whiteColor]; } - else if (TYPE == 5) + else if (type == 4) { - [self setLeftViewEnabledWithWidth:200.f + self.swipeGestureArea = LGSideMenuSwipeGestureAreaFull; + self.rootViewCoverColorForLeftView = [UIColor colorWithRed:0.f green:1.f blue:0.5 alpha:0.3]; + self.rootViewScaleForLeftView = 0.6; + self.rootViewLayerBorderWidth = 3.f; + self.rootViewLayerBorderColor = [UIColor whiteColor]; + self.rootViewLayerShadowRadius = 10.f; + self.rootViewCoverColorForRightView = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:0.3]; + + // ----- + + [self setLeftViewEnabledWithWidth:250.f presentationStyle:LGSideMenuPresentationStyleScaleFromBig - alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPadLandscape|LGSideMenuAlwaysVisibleOnPhoneLandscape]; + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + self.leftViewAnimationSpeed = 0.4; + self.leftViewStatusBarStyle = UIStatusBarStyleDefault; + self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; self.leftViewBackgroundImage = [UIImage imageNamed:@"image"]; self.leftViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; self.leftViewBackgroundImageInitialScale = 1.5; self.leftViewInititialOffsetX = -200.f; self.leftViewInititialScale = 1.5; - self.rootViewCoverColorForLeftView = [UIColor colorWithRed:0.f green:1.f blue:0.5 alpha:0.3]; - self.rootViewScaleForLeftView = 0.6; - self.rootViewLayerBorderWidth = 3.f; - self.rootViewLayerBorderColor = [UIColor whiteColor]; - self.rootViewLayerShadowRadius = 10.f; + _leftViewController.tableView.backgroundColor = [UIColor clearColor]; + _leftViewController.tintColor = [UIColor whiteColor]; // ----- [self setRightViewEnabledWithWidth:100.f presentationStyle:LGSideMenuPresentationStyleSlideAbove - alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnPadLandscape|LGSideMenuAlwaysVisibleOnPhoneLandscape]; + alwaysVisibleOptions:LGSideMenuAlwaysVisibleOnNone]; + self.rightViewAnimationSpeed = 0.3; + self.rightViewStatusBarStyle = UIStatusBarStyleDefault; + self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnNone; self.rightViewBackgroundColor = [UIColor colorWithWhite:1.f alpha:0.7]; self.rightViewStatusBarVisibleOptions = LGSideMenuStatusBarVisibleOnPadLandscape; self.rightViewLayerBorderWidth = 3.f; self.rightViewLayerBorderColor = [UIColor blackColor]; self.rightViewLayerShadowRadius = 10.f; - self.rootViewCoverColorForRightView = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:0.3]; - - // ----- - - _leftViewController.tableView.backgroundColor = [UIColor clearColor]; - _leftViewController.tintColor = [UIColor whiteColor]; - [_leftViewController.tableView reloadData]; - [self.leftView addSubview:_leftViewController.tableView]; - - // ----- - _rightViewController.tableView.backgroundColor = [UIColor clearColor]; _rightViewController.tintColor = [UIColor blackColor]; - [_rightViewController.tableView reloadData]; - [self.rightView addSubview:_rightViewController.tableView]; } + + // ----- + + [_leftViewController.tableView reloadData]; + [self.leftView addSubview:_leftViewController.tableView]; + + [_rightViewController.tableView reloadData]; + [self.rightView addSubview:_rightViewController.tableView]; } return self; } @@ -209,34 +255,20 @@ - (void)leftViewWillLayoutSubviewsWithSize:(CGSize)size { [super leftViewWillLayoutSubviewsWithSize:size]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && (TYPE == 4 || TYPE == 5)) - { - if (self.isLeftViewAlwaysVisible) - { - _leftViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); - _leftViewController.tableView.contentInset = UIEdgeInsetsMake(0.f, 0.f, 20.f, 0.f); - } - else - { - _leftViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); - _leftViewController.tableView.contentInset = UIEdgeInsetsMake(20.f, 0.f, 20.f, 0.f); - } - } - else _leftViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); + if (![UIApplication sharedApplication].isStatusBarHidden && (_type == 2 || _type == 3)) + _leftViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); + else + _leftViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); } - (void)rightViewWillLayoutSubviewsWithSize:(CGSize)size { [super rightViewWillLayoutSubviewsWithSize:size]; - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && (TYPE == 4 || TYPE == 5)) - { - if (self.isLeftViewAlwaysVisible) - _rightViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); - else - _rightViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); - } - else _rightViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); + if (![UIApplication sharedApplication].isStatusBarHidden && (_type == 2 || _type == 3)) + _rightViewController.tableView.frame = CGRectMake(0.f , 20.f, size.width, size.height-20.f); + else + _rightViewController.tableView.frame = CGRectMake(0.f , 0.f, size.width, size.height); } @end diff --git a/Demo/LGSideMenuControllerDemo/NavigationController.h b/Demo/LGSideMenuControllerDemo/NavigationController.h new file mode 100644 index 0000000..6ca74a6 --- /dev/null +++ b/Demo/LGSideMenuControllerDemo/NavigationController.h @@ -0,0 +1,13 @@ +// +// NavigationController.h +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright © 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface NavigationController : UINavigationController + +@end diff --git a/Demo/LGSideMenuControllerDemo/NavigationController.m b/Demo/LGSideMenuControllerDemo/NavigationController.m new file mode 100644 index 0000000..2d1ea3c --- /dev/null +++ b/Demo/LGSideMenuControllerDemo/NavigationController.m @@ -0,0 +1,45 @@ +// +// NavigationController.m +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright © 2015 Grigory Lutkov. All rights reserved. +// + +#import "NavigationController.h" + +@interface NavigationController () + +@end + +@implementation NavigationController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.navigationBar.translucent = YES; + self.navigationBar.barTintColor = [UIColor whiteColor]; +} + +- (BOOL)shouldAutorotate +{ + return YES; +} + +- (BOOL)prefersStatusBarHidden +{ + return (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone); +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleDefault; +} + +- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation +{ + return UIStatusBarAnimationNone; +} + +@end diff --git a/Demo/LGSideMenuControllerDemo/RightViewController.m b/Demo/LGSideMenuControllerDemo/RightViewController.m index e0c3cfd..f6dfbed 100644 --- a/Demo/LGSideMenuControllerDemo/RightViewController.m +++ b/Demo/LGSideMenuControllerDemo/RightViewController.m @@ -10,6 +10,8 @@ #import "AppDelegate.h" #import "RightViewCell.h" #import "ViewController.h" +#import "MainViewController.h" +#import "NavigationController.h" @interface RightViewController () @@ -24,8 +26,7 @@ - (id)init self = [super initWithStyle:UITableViewStylePlain]; if (self) { - _titlesArray = @[@"Set VC", - @"Open Left View", + _titlesArray = @[@"Open Left View", @"", @"1", @"2", @@ -40,23 +41,12 @@ - (id)init [self.tableView registerClass:[RightViewCell class] forCellReuseIdentifier:@"cell"]; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; + self.tableView.contentInset = UIEdgeInsetsMake(44.f, 0.f, 44.f, 0.f); self.tableView.showsVerticalScrollIndicator = NO; } return self; } -#pragma mark - - -- (void)openLeftView -{ - [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; -} - -- (void)openRightView -{ - [kMainViewController showRightViewAnimated:YES completionHandler:nil]; -} - #pragma mark - UITableView DataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -76,12 +66,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N RightViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; cell.textLabel.text = _titlesArray[indexPath.row]; - if (indexPath.row < 3) + if (indexPath.row == 0) cell.textLabel.font = [UIFont boldSystemFontOfSize:15.f]; else cell.textLabel.font = [UIFont boldSystemFontOfSize:30.f]; - cell.separatorView.hidden = !(indexPath.row != _titlesArray.count-1 && indexPath.row != 1 && indexPath.row != 2); - cell.userInteractionEnabled = (indexPath.row != 2); + cell.separatorView.hidden = !(indexPath.row != 0 && indexPath.row != 1 && indexPath.row != _titlesArray.count-1); + cell.userInteractionEnabled = (indexPath.row != 1); cell.tintColor = _tintColor; @@ -90,7 +80,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - if (indexPath.row == 2) return 50.f; + if (indexPath.row == 1) return 50.f; else return 100.f; } @@ -98,19 +88,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath { if (indexPath.row == 0) { - ViewController *viewController = [ViewController new]; - - UIViewController *viewController2 = [UIViewController new]; - viewController2.view.backgroundColor = [UIColor whiteColor]; - viewController2.title = @"Test"; - - [kNavigationController setViewControllers:@[viewController, viewController2]]; - - [kMainViewController hideRightViewAnimated:YES completionHandler:nil]; - } - else if (indexPath.row == 1) - { - if (!kMainViewController.isRightViewAlwaysVisible) + if (![kMainViewController isRightViewAlwaysVisible]) { [kMainViewController hideRightViewAnimated:YES completionHandler:^(void) { diff --git a/Demo/LGSideMenuControllerDemo/TableViewController.h b/Demo/LGSideMenuControllerDemo/TableViewController.h new file mode 100644 index 0000000..61a10d8 --- /dev/null +++ b/Demo/LGSideMenuControllerDemo/TableViewController.h @@ -0,0 +1,13 @@ +// +// TableViewController.h +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import + +@interface TableViewController : UITableViewController + +@end diff --git a/Demo/LGSideMenuControllerDemo/TableViewController.m b/Demo/LGSideMenuControllerDemo/TableViewController.m new file mode 100644 index 0000000..8a9bd13 --- /dev/null +++ b/Demo/LGSideMenuControllerDemo/TableViewController.m @@ -0,0 +1,126 @@ +// +// TableViewController.m +// LGSideMenuControllerDemo +// +// Created by Grigory Lutkov on 05.11.15. +// Copyright (c) 2015 Grigory Lutkov. All rights reserved. +// + +#import "TableViewController.h" +#import "MainViewController.h" +#import "NavigationController.h" +#import "ViewController.h" + +@interface TableViewController () + +@property (strong, nonatomic) NSArray *titlesArray; + +@end + +@implementation TableViewController + +- (id)init +{ + self = [super initWithStyle:UITableViewStylePlain]; + if (self) + { + self.title = @"LGSideMenuController"; + + _titlesArray = @[@"Style Scale From Big", + @"Style Slide Above", + @"Style Slide Below", + @"Style Scale From Little", + @"Landscape always visible", + @"Status bar always visible", + @"Status bar light content", + @"Custom style"]; + + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + + self.clearsSelectionOnViewWillAppear = NO; + } + return self; +} + +#pragma mark - UITableView DataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return _titlesArray.count; +} + +#pragma mark - UITableView Delegate + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; + + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + + cell.textLabel.font = [UIFont systemFontOfSize:16.f]; + cell.textLabel.text = _titlesArray[indexPath.row]; + + return cell; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return 44.f; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + ViewController *viewController = [ViewController new]; + NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:viewController]; + MainViewController *mainViewController = nil; + + if (indexPath.row == 0) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleScaleFromBig + type:0]; + else if (indexPath.row == 1) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleSlideAbove + type:0]; + else if (indexPath.row == 2) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleSlideBelow + type:0]; + else if (indexPath.row == 3) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleScaleFromLittle + type:0]; + else if (indexPath.row == 4) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleScaleFromBig + type:1]; + else if (indexPath.row == 5) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleSlideAbove + type:2]; + else if (indexPath.row == 6) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:LGSideMenuPresentationStyleSlideAbove + type:3]; + else if (indexPath.row == 7) + mainViewController = [[MainViewController alloc] initWithRootViewController:navigationController + presentationStyle:0 + type:4]; + + UIWindow *window = [UIApplication sharedApplication].delegate.window; + + window.rootViewController = mainViewController; + + [UIView transitionWithView:window + duration:0.3 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:nil + completion:nil]; +} + +@end diff --git a/Demo/LGSideMenuControllerDemo/ViewController.m b/Demo/LGSideMenuControllerDemo/ViewController.m index cc0c4be..18f6faf 100644 --- a/Demo/LGSideMenuControllerDemo/ViewController.m +++ b/Demo/LGSideMenuControllerDemo/ViewController.m @@ -8,6 +8,9 @@ #import "ViewController.h" #import "AppDelegate.h" +#import "ChooseNavigationController.h" +#import "TableViewController.h" +#import "MainViewController.h" @interface ViewController () @@ -35,15 +38,16 @@ - (id)init _button = [UIButton new]; _button.backgroundColor = [UIColor colorWithWhite:1.f alpha:0.5]; - [_button setTitle:@"Push View Controller" forState:UIControlStateNormal]; + [_button setTitle:@"Show Choose Controller" forState:UIControlStateNormal]; [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [_button setTitleColor:[UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f] forState:UIControlStateHighlighted]; - [_button addTarget:self action:@selector(pushViewControllerAction) forControlEvents:UIControlEventTouchUpInside]; + [_button addTarget:self action:@selector(showChooseController) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_button]; // ----- - [self checkNavItemButtonsWithInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation]; + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(openLeftView)]; + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(openRightView)]; } return self; } @@ -59,45 +63,6 @@ - (void)viewWillLayoutSubviews #pragma mark - -- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator -{ - [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; - - UIInterfaceOrientation interfaceOrientation = (size.width < size.height ? UIInterfaceOrientationPortrait : UIInterfaceOrientationLandscapeLeft); - - [self checkNavItemButtonsWithInterfaceOrientation:interfaceOrientation]; -} - -- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration -{ - [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; - - [self checkNavItemButtonsWithInterfaceOrientation:toInterfaceOrientation]; -} - -- (void)checkNavItemButtonsWithInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - if (TYPE == 4 || TYPE == 5) - { - if ([kMainViewController isLeftViewAlwaysVisibleForInterfaceOrientation:interfaceOrientation]) - self.navigationItem.leftBarButtonItem = nil; - else - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(openLeftView)]; - - if ([kMainViewController isRightViewAlwaysVisibleForInterfaceOrientation:interfaceOrientation]) - self.navigationItem.rightBarButtonItem = nil; - else - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(openRightView)]; - } - else - { - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(openLeftView)]; - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(openRightView)]; - } -} - -#pragma mark - - - (void)openLeftView { [kMainViewController showLeftViewAnimated:YES completionHandler:nil]; @@ -108,12 +73,20 @@ - (void)openRightView [kMainViewController showRightViewAnimated:YES completionHandler:nil]; } -- (void)pushViewControllerAction +- (void)showChooseController { - UIViewController *viewController = [UIViewController new]; - viewController.view.backgroundColor = [UIColor whiteColor]; - viewController.title = @"Test"; - [self.navigationController pushViewController:viewController animated:YES]; + TableViewController *viewController = [TableViewController new]; + ChooseNavigationController *navigationController = [[ChooseNavigationController alloc] initWithRootViewController:viewController]; + + UIWindow *window = [UIApplication sharedApplication].delegate.window; + + window.rootViewController = navigationController; + + [UIView transitionWithView:window + duration:0.3 + options:UIViewAnimationOptionTransitionCrossDissolve + animations:nil + completion:nil]; } @end diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 87ff06d..96d7bb3 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - LGSideMenuController (1.0.4) + - LGSideMenuController (1.0.5) DEPENDENCIES: - LGSideMenuController (from `../`) @@ -9,6 +9,6 @@ EXTERNAL SOURCES: :path: ../ SPEC CHECKSUMS: - LGSideMenuController: a9296cca27657824443b945323cfb49ea4254482 + LGSideMenuController: 0b3a8a9e33d5ae16fada970566e14dc5b413bafc COCOAPODS: 0.39.0 diff --git a/LGSideMenuController.podspec b/LGSideMenuController.podspec index 5735065..60957a3 100644 --- a/LGSideMenuController.podspec +++ b/LGSideMenuController.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'LGSideMenuController' - s.version = '1.0.4' + s.version = '1.0.5' s.platform = :ios, '6.0' s.license = 'MIT' s.homepage = 'https://github.com/Friend-LGA/LGSideMenuController' diff --git a/LGSideMenuController/LGSideMenuController.h b/LGSideMenuController/LGSideMenuController.h index 4acb709..96e052e 100644 --- a/LGSideMenuController/LGSideMenuController.h +++ b/LGSideMenuController/LGSideMenuController.h @@ -48,6 +48,7 @@ typedef enum LGSideMenuAlwaysVisibleOnPadPortrait = 1 << 1, LGSideMenuAlwaysVisibleOnPhoneLandscape = 1 << 2, LGSideMenuAlwaysVisibleOnPhonePortrait = 1 << 3, + LGSideMenuAlwaysVisibleOnAll = 1 << 4 } LGSideMenuAlwaysVisibleOptions; @@ -58,6 +59,7 @@ typedef enum LGSideMenuStatusBarVisibleOnPadPortrait = 1 << 1, LGSideMenuStatusBarVisibleOnPhoneLandscape = 1 << 2, LGSideMenuStatusBarVisibleOnPhonePortrait = 1 << 3, + LGSideMenuStatusBarVisibleOnAll = 1 << 4 } LGSideMenuStatusBarVisibleOptions; @@ -70,6 +72,15 @@ typedef enum } LGSideMenuPresentationStyle; +typedef enum +{ + LGSideMenuSwipeGestureAreaBorders = 0, + LGSideMenuSwipeGestureAreaFull = 1 +} +LGSideMenuSwipeGestureArea; + +@property (assign, nonatomic) IBOutlet UIViewController *rootViewController; + @property (assign, nonatomic, readonly) CGFloat leftViewWidth; @property (assign, nonatomic, readonly) CGFloat rightViewWidth; @@ -82,8 +93,14 @@ LGSideMenuPresentationStyle; @property (assign, nonatomic) IBInspectable LGSideMenuStatusBarVisibleOptions leftViewStatusBarVisibleOptions; @property (assign, nonatomic) IBInspectable LGSideMenuStatusBarVisibleOptions rightViewStatusBarVisibleOptions; -@property (assign, nonatomic, getter=isLeftViewShowing) BOOL leftViewShowing; -@property (assign, nonatomic, getter=isRightViewShowing) BOOL rightViewShowing; +@property (assign, nonatomic) IBInspectable UIStatusBarStyle leftViewStatusBarStyle; +@property (assign, nonatomic) IBInspectable UIStatusBarStyle rightViewStatusBarStyle; + +@property (assign, nonatomic) IBInspectable UIStatusBarAnimation leftViewStatusBarUpdateAnimation; +@property (assign, nonatomic) IBInspectable UIStatusBarAnimation rightViewStatusBarUpdateAnimation; + +@property (assign, nonatomic, readonly, getter=isLeftViewShowing) BOOL leftViewShowing; +@property (assign, nonatomic, readonly, getter=isRightViewShowing) BOOL rightViewShowing; /** Default is YES */ @property (assign, nonatomic, getter=isLeftViewHidesOnTouch) IBInspectable BOOL leftViewHidesOnTouch; @@ -97,6 +114,9 @@ LGSideMenuPresentationStyle; /** Default is YES */ @property (assign, nonatomic, getter=isGesturesCancelsTouchesInView) IBInspectable BOOL gesturesCancelsTouchesInView; +/** Default is LGSideMenuSwipeGestureAreaBorders */ +@property (assign, nonatomic) IBInspectable LGSideMenuSwipeGestureArea swipeGestureArea; + /** Color that hides root view, when left view is showing For LGSideMenuPresentationStyleSlideAbove default is [UIColor colorWithWhite:0.f alpha:0.5] @@ -206,12 +226,13 @@ LGSideMenuPresentationStyle; @property (strong, nonatomic) IBInspectable UIColor *rightViewLayerShadowColor; /** For LGSideMenuPresentationStyleSlideAbove default is 5.f */ @property (assign, nonatomic) IBInspectable CGFloat rightViewLayerShadowRadius; +/** Default is 0.5 */ +@property (assign, nonatomic) IBInspectable NSTimeInterval leftViewAnimationSpeed; +/** Default is 0.5 */ +@property (assign, nonatomic) IBInspectable NSTimeInterval rightViewAnimationSpeed; - (instancetype)initWithRootViewController:(UIViewController *)rootViewController; -- (void)setRootViewController:(UIViewController *)rootViewController; - -- (UIViewController *)rootViewController; - (UIView *)leftView; - (UIView *)rightView; @@ -240,4 +261,13 @@ LGSideMenuPresentationStyle; - (void)hideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showHideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; +/** Unavailable, select it on your rootViewController */ +- (BOOL)shouldAutorotate __attribute__((unavailable("select it on your rootViewController"))); +/** Unavailable, select it on your rootViewController */ +- (BOOL)prefersStatusBarHidden __attribute__((unavailable("select it on your rootViewController"))); +/** Unavailable, select it on your rootViewController */ +- (UIStatusBarStyle)preferredStatusBarStyle __attribute__((unavailable("select it on your rootViewController"))); +/** Unavailable, select it on your rootViewController */ +- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation __attribute__((unavailable("select it on your rootViewController"))); + @end diff --git a/LGSideMenuController/LGSideMenuController.m b/LGSideMenuController/LGSideMenuController.m index 0432bf8..a6ac922 100644 --- a/LGSideMenuController/LGSideMenuController.m +++ b/LGSideMenuController/LGSideMenuController.m @@ -36,54 +36,61 @@ #define kLGSideMenuDeviceIsPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) #define kLGSideMenuSystemVersion UIDevice.currentDevice.systemVersion.floatValue #define kLGSideMenuCoverColor [UIColor colorWithWhite:0.f alpha:0.5] +#define kLGSideMenuIsMenuShowing (self.isLeftViewShowing || self.isRightViewShowing) #define kLGSideMenuIsLeftViewAlwaysVisible \ +((_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnAll) || \ ((kLGSideMenuDeviceIsPhone && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhonePortrait)) || \ (kLGSideMenuStatusBarOrientationIsLandscape && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhoneLandscape)))) || \ (kLGSideMenuDeviceIsPad && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadPortrait)) || \ -(kLGSideMenuStatusBarOrientationIsLandscape && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape))))) +(kLGSideMenuStatusBarOrientationIsLandscape && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape)))))) #define kLGSideMenuIsRightViewAlwaysVisible \ +((_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnAll) || \ ((kLGSideMenuDeviceIsPhone && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhonePortrait)) || \ (kLGSideMenuStatusBarOrientationIsLandscape && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhoneLandscape)))) || \ (kLGSideMenuDeviceIsPad && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadPortrait)) || \ -(kLGSideMenuStatusBarOrientationIsLandscape && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape))))) +(kLGSideMenuStatusBarOrientationIsLandscape && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape)))))) #define kLGSideMenuIsLeftViewAlwaysVisibleForInterfaceOrientation(interfaceOrientation) \ +((_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnAll) || \ ((kLGSideMenuDeviceIsPhone && \ ((UIInterfaceOrientationIsPortrait(interfaceOrientation) && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhonePortrait)) || \ (UIInterfaceOrientationIsLandscape(interfaceOrientation) && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhoneLandscape)))) || \ (kLGSideMenuDeviceIsPad && \ ((UIInterfaceOrientationIsPortrait(interfaceOrientation) && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadPortrait)) || \ -(UIInterfaceOrientationIsLandscape(interfaceOrientation) && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape))))) +(UIInterfaceOrientationIsLandscape(interfaceOrientation) && (_leftViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape)))))) #define kLGSideMenuIsRightViewAlwaysVisibleForInterfaceOrientation(interfaceOrientation) \ +((_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnAll) || \ ((kLGSideMenuDeviceIsPhone && \ ((UIInterfaceOrientationIsPortrait(interfaceOrientation) && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhonePortrait)) || \ (UIInterfaceOrientationIsLandscape(interfaceOrientation) && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPhoneLandscape)))) || \ (kLGSideMenuDeviceIsPad && \ ((UIInterfaceOrientationIsPortrait(interfaceOrientation) && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadPortrait)) || \ -(UIInterfaceOrientationIsLandscape(interfaceOrientation) && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape))))) +(UIInterfaceOrientationIsLandscape(interfaceOrientation) && (_rightViewAlwaysVisibleOptions & LGSideMenuAlwaysVisibleOnPadLandscape)))))) #define kLGSideMenuIsLeftViewStatusBarVisible \ +((_leftViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnAll) || \ ((kLGSideMenuDeviceIsPhone && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_leftViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPhonePortrait)) || \ (kLGSideMenuStatusBarOrientationIsLandscape && (_leftViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPhoneLandscape)))) || \ (kLGSideMenuDeviceIsPad && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_leftViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPadPortrait)) || \ -(kLGSideMenuStatusBarOrientationIsLandscape && (_leftViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPadLandscape))))) +(kLGSideMenuStatusBarOrientationIsLandscape && (_leftViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPadLandscape)))))) #define kLGSideMenuIsRightViewStatusBarVisible \ +((_rightViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnAll) || \ ((kLGSideMenuDeviceIsPhone && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_rightViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPhonePortrait)) || \ (kLGSideMenuStatusBarOrientationIsLandscape && (_rightViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPhoneLandscape)))) || \ (kLGSideMenuDeviceIsPad && \ ((kLGSideMenuStatusBarOrientationIsPortrait && (_rightViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPadPortrait)) || \ -(kLGSideMenuStatusBarOrientationIsLandscape && (_rightViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPadLandscape))))) +(kLGSideMenuStatusBarOrientationIsLandscape && (_rightViewStatusBarVisibleOptions & LGSideMenuStatusBarVisibleOnPadLandscape)))))) @interface LGSideMenuView : UIView @@ -128,14 +135,19 @@ @interface LGSideMenuController () @property (strong, nonatomic) UIView *leftViewCoverView; @property (strong, nonatomic) UIView *rightViewCoverView; -@property (strong, nonatomic) UIImageView *backgroundImageView; +@property (strong, nonatomic) UIImageView *backgroundImageViewForLeftView; +@property (strong, nonatomic) UIImageView *backgroundImageViewForRightView; @property (strong, nonatomic) UIView *rootViewStyleView; @property (strong, nonatomic) UIView *leftViewStyleView; @property (strong, nonatomic) UIView *rightViewStyleView; @property (assign, nonatomic) BOOL savedStatusBarHidden; -@property (assign, nonatomic) BOOL currentStatusBarHidden; + +@property (assign, nonatomic) BOOL currentShouldAutorotate; +@property (assign, nonatomic) BOOL currentPreferredStatusBarHidden; +@property (assign, nonatomic) UIStatusBarStyle currentPreferredStatusBarStyle; +@property (assign, nonatomic) UIStatusBarAnimation currentPreferredStatusBarUpdateAnimation; @property (strong, nonatomic) NSNumber *leftViewGestireStartX; @property (strong, nonatomic) NSNumber *rightViewGestireStartX; @@ -145,6 +157,20 @@ @interface LGSideMenuController () @property (strong, nonatomic) UIPanGestureRecognizer *panGesture; +@property (assign, nonatomic, getter=isUserRootViewScaleForLeftView) BOOL userRootViewScaleForLeftView; +@property (assign, nonatomic, getter=isUserRootViewCoverColorForLeftView) BOOL userRootViewCoverColorForLeftView; +@property (assign, nonatomic, getter=isUserLeftViewCoverColor) BOOL userLeftViewCoverColor; +@property (assign, nonatomic, getter=isUserLeftViewBackgroundImageInitialScale) BOOL userLeftViewBackgroundImageInitialScale; +@property (assign, nonatomic, getter=isUserLeftViewInititialScale) BOOL userLeftViewInititialScale; +@property (assign, nonatomic, getter=isUserLeftViewInititialOffsetX) BOOL userLeftViewInititialOffsetX; + +@property (assign, nonatomic, getter=isUserRootViewScaleForRightView) BOOL userRootViewScaleForRightView; +@property (assign, nonatomic, getter=isUserRootViewCoverColorForRightView) BOOL userRootViewCoverColorForRightView; +@property (assign, nonatomic, getter=isUserRightViewCoverColor) BOOL userRightViewCoverColor; +@property (assign, nonatomic, getter=isUserRightViewBackgroundImageInitialScale) BOOL userRightViewBackgroundImageInitialScale; +@property (assign, nonatomic, getter=isUserRightViewInititialScale) BOOL userRightViewInititialScale; +@property (assign, nonatomic, getter=isUserRightViewInititialOffsetX) BOOL userRightViewInititialOffsetX; + @end @implementation LGSideMenuController @@ -192,6 +218,9 @@ - (void)awakeFromNib - (void)setupDefaultProperties { + _leftViewAnimationSpeed = 0.5; + _rightViewAnimationSpeed = 0.5; + _leftViewHidesOnTouch = YES; _rightViewHidesOnTouch = YES; @@ -206,9 +235,6 @@ - (void)setupDefaultProperties _rightViewLayerShadowColor = [UIColor colorWithWhite:0.f alpha:0.5]; _rightViewLayerShadowRadius = 5.f; - - _leftViewCoverColor = kLGSideMenuCoverColor; - _rightViewCoverColor = kLGSideMenuCoverColor; } - (void)setupDefaults @@ -217,11 +243,19 @@ - (void)setupDefaults // ----- - _backgroundImageView = [UIImageView new]; - _backgroundImageView.hidden = YES; - _backgroundImageView.contentMode = UIViewContentModeScaleAspectFill; - _backgroundImageView.backgroundColor = [UIColor clearColor]; - [self.view addSubview:_backgroundImageView]; + _backgroundImageViewForLeftView = [UIImageView new]; + _backgroundImageViewForLeftView.hidden = YES; + _backgroundImageViewForLeftView.contentMode = UIViewContentModeScaleAspectFill; + _backgroundImageViewForLeftView.backgroundColor = [UIColor clearColor]; + _backgroundImageViewForLeftView.clipsToBounds = YES; + [self.view addSubview:_backgroundImageViewForLeftView]; + + _backgroundImageViewForRightView = [UIImageView new]; + _backgroundImageViewForRightView.hidden = YES; + _backgroundImageViewForRightView.contentMode = UIViewContentModeScaleAspectFill; + _backgroundImageViewForRightView.backgroundColor = [UIColor clearColor]; + _backgroundImageViewForRightView.clipsToBounds = YES; + [self.view addSubview:_backgroundImageViewForRightView]; // ----- @@ -301,16 +335,121 @@ - (void)viewWillLayoutSubviews - (BOOL)shouldAutorotate { - return !(self.isLeftViewShowing || self.isRightViewShowing); + return (kLGSideMenuIsMenuShowing ? _currentShouldAutorotate : (_rootVC ? _rootVC.shouldAutorotate : YES)); } - (BOOL)prefersStatusBarHidden { - return _currentStatusBarHidden; + return (kLGSideMenuIsMenuShowing ? _currentPreferredStatusBarHidden : (_rootVC ? _rootVC.prefersStatusBarHidden : (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))); +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return (kLGSideMenuIsMenuShowing ? _currentPreferredStatusBarStyle : (_rootVC ? _rootVC.preferredStatusBarStyle : UIStatusBarStyleDefault)); +} + +- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation +{ + return (kLGSideMenuIsMenuShowing ? _currentPreferredStatusBarUpdateAnimation : (_rootVC ? _rootVC.preferredStatusBarUpdateAnimation : UIStatusBarAnimationNone)); +} + +- (void)statusBarAppearanceUpdate +{ +#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 + if (kLGSideMenuSystemVersion < 9.0) + { + [[UIApplication sharedApplication] setStatusBarHidden:_currentPreferredStatusBarHidden withAnimation:_currentPreferredStatusBarUpdateAnimation]; + [[UIApplication sharedApplication] setStatusBarStyle:_currentPreferredStatusBarStyle animated:_currentPreferredStatusBarUpdateAnimation]; + } +#endif } #pragma mark - Setters and Getters +- (void)setRootViewScaleForLeftView:(CGFloat)rootViewScaleForLeftView +{ + _rootViewScaleForLeftView = rootViewScaleForLeftView; + + _userRootViewScaleForLeftView = YES; +} + +- (void)setRootViewScaleForRightView:(CGFloat)rootViewScaleForRightView +{ + _rootViewScaleForRightView = rootViewScaleForRightView; + + _userRootViewScaleForRightView = YES; +} + +- (void)setRootViewCoverColorForLeftView:(UIColor *)rootViewCoverColorForLeftView +{ + _rootViewCoverColorForLeftView = rootViewCoverColorForLeftView; + + _userRootViewCoverColorForLeftView = YES; +} + +- (void)setRootViewCoverColorForRightView:(UIColor *)rootViewCoverColorForRightView +{ + _rootViewCoverColorForRightView = rootViewCoverColorForRightView; + + _userRootViewCoverColorForRightView = YES; +} + +- (void)setLeftViewCoverColor:(UIColor *)leftViewCoverColor +{ + _leftViewCoverColor = leftViewCoverColor; + + _userLeftViewCoverColor = YES; +} + +- (void)setRightViewCoverColor:(UIColor *)rightViewCoverColor +{ + _rightViewCoverColor = rightViewCoverColor; + + _userRightViewCoverColor = YES; +} + +- (void)setLeftViewBackgroundImageInitialScale:(CGFloat)leftViewBackgroundImageInitialScale +{ + _leftViewBackgroundImageInitialScale = leftViewBackgroundImageInitialScale; + + _userLeftViewBackgroundImageInitialScale = YES; +} + +- (void)setRightViewBackgroundImageInitialScale:(CGFloat)rightViewBackgroundImageInitialScale +{ + _rightViewBackgroundImageInitialScale = rightViewBackgroundImageInitialScale; + + _userRightViewBackgroundImageInitialScale = YES; +} + +- (void)setLeftViewInititialScale:(CGFloat)leftViewInititialScale +{ + _leftViewInititialScale = leftViewInititialScale; + + _userLeftViewInititialScale = YES; +} + +- (void)setRightViewInititialScale:(CGFloat)rightViewInititialScale +{ + _rightViewInititialScale = rightViewInititialScale; + + _userRightViewInititialScale = YES; +} + +- (void)setLeftViewInititialOffsetX:(CGFloat)leftViewInititialOffsetX +{ + _leftViewInititialOffsetX = leftViewInititialOffsetX; + + _userLeftViewInititialOffsetX = YES; +} + +- (void)setRightViewInititialOffsetX:(CGFloat)rightViewInititialOffsetX +{ + _rightViewInititialOffsetX = rightViewInititialOffsetX; + + _userRightViewInititialOffsetX = YES; +} + - (void)setRootViewController:(UIViewController *)rootViewController { if (rootViewController) @@ -374,22 +513,6 @@ - (UIView *)rightView return _rightView; } -- (void)setRootViewCoverColorForLeftView:(UIColor *)rootViewCoverColorForLeftView -{ - _rootViewCoverColorForLeftView = rootViewCoverColorForLeftView; - - if (_leftView) - _rootViewCoverViewForLeftView.backgroundColor = _rootViewCoverColorForLeftView; -} - -- (void)setRootViewCoverColorForRightView:(UIColor *)rootViewCoverColorForRightView -{ - _rootViewCoverColorForRightView = rootViewCoverColorForRightView; - - if (_rightView) - _rootViewCoverViewForRightView.backgroundColor = _rootViewCoverColorForRightView; -} - - (BOOL)isLeftViewAlwaysVisible { return kLGSideMenuIsLeftViewAlwaysVisible; @@ -436,10 +559,10 @@ - (void)rootViewLayoutInvalidateWithPercentage:(CGFloat)percentage _rootVC.view.transform = CGAffineTransformIdentity; _rootViewStyleView.transform = CGAffineTransformIdentity; - if (_leftView) + if (_rootViewCoverViewForLeftView) _rootViewCoverViewForLeftView.transform = CGAffineTransformIdentity; - if (_rightView) + if (_rootViewCoverViewForRightView) _rootViewCoverViewForRightView.transform = CGAffineTransformIdentity; // ----- @@ -546,7 +669,7 @@ - (void)leftViewLayoutInvalidateWithPercentage:(CGFloat)percentage // ----- _leftView.transform = CGAffineTransformIdentity; - _backgroundImageView.transform = CGAffineTransformIdentity; + _backgroundImageViewForLeftView.transform = CGAffineTransformIdentity; _leftViewStyleView.transform = CGAffineTransformIdentity; // ----- @@ -588,11 +711,19 @@ - (void)leftViewLayoutInvalidateWithPercentage:(CGFloat)percentage if (_leftViewPresentationStyle != LGSideMenuPresentationStyleSlideAbove) { CGRect backgroundViewFrame = CGRectMake(0.f, 0.f, size.width, size.height); + + if (kLGSideMenuIsLeftViewAlwaysVisible && kLGSideMenuIsRightViewAlwaysVisible) + { + CGFloat multiplier = _rightViewWidth/_leftViewWidth; + + backgroundViewFrame.size.width = (size.width/(multiplier+1.f)); + } + if ([UIScreen mainScreen].scale == 1.f) backgroundViewFrame = CGRectIntegral(backgroundViewFrame); - _backgroundImageView.frame = backgroundViewFrame; + _backgroundImageViewForLeftView.frame = backgroundViewFrame; - _backgroundImageView.transform = backgroundViewTransform; + _backgroundImageViewForLeftView.transform = backgroundViewTransform; // ----- @@ -630,7 +761,7 @@ - (void)rightViewLayoutInvalidateWithPercentage:(CGFloat)percentage // ----- _rightView.transform = CGAffineTransformIdentity; - _backgroundImageView.transform = CGAffineTransformIdentity; + _backgroundImageViewForRightView.transform = CGAffineTransformIdentity; _rightViewStyleView.transform = CGAffineTransformIdentity; // ----- @@ -672,11 +803,20 @@ - (void)rightViewLayoutInvalidateWithPercentage:(CGFloat)percentage if (_rightViewPresentationStyle != LGSideMenuPresentationStyleSlideAbove) { CGRect backgroundViewFrame = CGRectMake(0.f, 0.f, size.width, size.height); + + if (kLGSideMenuIsLeftViewAlwaysVisible && kLGSideMenuIsRightViewAlwaysVisible) + { + CGFloat multiplier = _leftViewWidth/_rightViewWidth; + + backgroundViewFrame.size.width = (size.width/(multiplier+1.f)); + backgroundViewFrame.origin.x = size.width - backgroundViewFrame.size.width; + } + if ([UIScreen mainScreen].scale == 1.f) backgroundViewFrame = CGRectIntegral(backgroundViewFrame); - _backgroundImageView.frame = backgroundViewFrame; + _backgroundImageViewForRightView.frame = backgroundViewFrame; - _backgroundImageView.transform = backgroundViewTransform; + _backgroundImageViewForRightView.transform = backgroundViewTransform; // ----- @@ -699,14 +839,6 @@ - (void)rightViewLayoutInvalidateWithPercentage:(CGFloat)percentage - (void)colorsInvalidate { - _rootVC.view.layer.cornerRadius = 0.f; - _rootVC.view.layer.borderWidth = 0.f; - _rootVC.view.layer.borderColor = nil; - _rootVC.view.layer.shadowColor = nil; - _rootVC.view.layer.shadowOpacity = 0.f; - _rootVC.view.layer.shadowRadius = 0.f; - _rootVC.view.layer.shadowOffset = CGSizeZero; - if (_rootViewStyleView) { _rootViewStyleView.layer.borderWidth = _rootViewLayerBorderWidth; @@ -717,15 +849,6 @@ - (void)colorsInvalidate if (kLGSideMenuIsLeftViewAlwaysVisible || self.isLeftViewShowing) { - _leftView.backgroundColor = [UIColor clearColor]; - _leftView.layer.cornerRadius = 0.f; - _leftView.layer.borderWidth = 0.f; - _leftView.layer.borderColor = nil; - _leftView.layer.shadowColor = nil; - _leftView.layer.shadowOpacity = 0.f; - _leftView.layer.shadowRadius = 0.f; - _leftView.layer.shadowOffset = CGSizeZero; - self.view.backgroundColor = [_leftViewBackgroundColor colorWithAlphaComponent:1.f]; _rootViewCoverViewForLeftView.backgroundColor = _rootViewCoverColorForLeftView; @@ -743,20 +866,11 @@ - (void)colorsInvalidate } if (_leftViewBackgroundImage) - _backgroundImageView.image = _leftViewBackgroundImage; + _backgroundImageViewForLeftView.image = _leftViewBackgroundImage; } if (kLGSideMenuIsRightViewAlwaysVisible || self.isRightViewShowing) { - _rightView.backgroundColor = [UIColor clearColor]; - _rightView.layer.cornerRadius = 0.f; - _rightView.layer.borderWidth = 0.f; - _rightView.layer.borderColor = nil; - _rightView.layer.shadowColor = nil; - _rightView.layer.shadowOpacity = 0.f; - _rightView.layer.shadowRadius = 0.f; - _rightView.layer.shadowOffset = CGSizeZero; - self.view.backgroundColor = [_rightViewBackgroundColor colorWithAlphaComponent:1.f]; _rootViewCoverViewForRightView.backgroundColor = _rootViewCoverColorForRightView; @@ -774,7 +888,7 @@ - (void)colorsInvalidate } if (_rightViewBackgroundImage) - _backgroundImageView.image = _rightViewBackgroundImage; + _backgroundImageViewForRightView.image = _rightViewBackgroundImage; } } @@ -788,22 +902,17 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay BOOL rootViewStyleViewHiddenForLeftView = YES; BOOL rootViewStyleViewHiddenForRightView = YES; - BOOL backgroundImageViewHiddenForLeftView = YES; - BOOL backgroundImageViewHiddenForRightView = YES; - // ----- if (kLGSideMenuIsLeftViewAlwaysVisible) { _rootViewCoverViewForLeftView.hidden = YES; _leftViewCoverView.hidden = YES; - _leftView.hidden = NO; _leftViewStyleView.hidden = NO; - rootViewStyleViewHiddenForLeftView = NO; + _backgroundImageViewForLeftView.hidden = NO; - if (_leftViewBackgroundImage) - backgroundImageViewHiddenForLeftView = NO; + rootViewStyleViewHiddenForLeftView = NO; } else if (!self.isLeftViewShowing) { @@ -815,6 +924,7 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay _leftViewCoverView.hidden = YES; _leftView.hidden = YES; _leftViewStyleView.hidden = YES; + _backgroundImageViewForLeftView.hidden = YES; }); } else @@ -823,10 +933,10 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay _leftViewCoverView.hidden = YES; _leftView.hidden = YES; _leftViewStyleView.hidden = YES; + _backgroundImageViewForLeftView.hidden = YES; } rootViewStyleViewHiddenForLeftView = YES; - backgroundImageViewHiddenForLeftView = YES; } else if (self.isLeftViewShowing) { @@ -834,10 +944,9 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay _leftViewCoverView.hidden = NO; _leftView.hidden = NO; _leftViewStyleView.hidden = NO; - rootViewStyleViewHiddenForLeftView = NO; + _backgroundImageViewForLeftView.hidden = NO; - if (_leftViewBackgroundImage) - backgroundImageViewHiddenForLeftView = NO; + rootViewStyleViewHiddenForLeftView = NO; } // ----- @@ -846,13 +955,11 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay { _rootViewCoverViewForRightView.hidden = YES; _rightViewCoverView.hidden = YES; - _rightView.hidden = NO; _rightViewStyleView.hidden = NO; - rootViewStyleViewHiddenForRightView = NO; + _backgroundImageViewForRightView.hidden = NO; - if (_rightViewBackgroundImage) - backgroundImageViewHiddenForRightView = NO; + rootViewStyleViewHiddenForRightView = NO; } else if (!self.isRightViewShowing) { @@ -864,6 +971,7 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay _rightViewCoverView.hidden = YES; _rightView.hidden = YES; _rightViewStyleView.hidden = YES; + _backgroundImageViewForRightView.hidden = YES; }); } else @@ -872,10 +980,10 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay _rightViewCoverView.hidden = YES; _rightView.hidden = YES; _rightViewStyleView.hidden = YES; + _backgroundImageViewForRightView.hidden = YES; } rootViewStyleViewHiddenForRightView = YES; - backgroundImageViewHiddenForRightView = YES; } else if (self.isRightViewShowing) { @@ -883,10 +991,9 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay _rightViewCoverView.hidden = NO; _rightView.hidden = NO; _rightViewStyleView.hidden = NO; - rootViewStyleViewHiddenForRightView = NO; + _backgroundImageViewForRightView.hidden = NO; - if (_rightViewBackgroundImage) - backgroundImageViewHiddenForRightView = NO; + rootViewStyleViewHiddenForRightView = NO; } // ----- @@ -903,19 +1010,6 @@ - (void)hiddensInvalidateWithDelay:(NSTimeInterval)delay else _rootViewStyleView.hidden = (rootViewStyleViewHiddenForLeftView && rootViewStyleViewHiddenForRightView); } else _rootViewStyleView.hidden = NO; - - if (backgroundImageViewHiddenForLeftView && backgroundImageViewHiddenForRightView) - { - if (delay) - { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^(void) - { - _backgroundImageView.hidden = YES; - }); - } - else _backgroundImageView.hidden = YES; - } - else _backgroundImageView.hidden = NO; } #pragma mark - Side Views @@ -924,251 +1018,267 @@ - (void)setLeftViewEnabledWithWidth:(CGFloat)width presentationStyle:(LGSideMenuPresentationStyle)presentationStyle alwaysVisibleOptions:(LGSideMenuAlwaysVisibleOptions)alwaysVisibleOptions { - if (!_leftView) + NSAssert(_leftView == nil, @"Left view already exists"); + + _rootViewCoverViewForLeftView = [UIView new]; + _rootViewCoverViewForLeftView.hidden = YES; + if (_rootVC) { - _rootViewCoverViewForLeftView = [UIView new]; - _rootViewCoverViewForLeftView.hidden = YES; - if (_rootVC) - { - if (_rootViewCoverViewForRightView) - [self.view insertSubview:_rootViewCoverViewForLeftView aboveSubview:_rootViewCoverViewForRightView]; - else - [self.view addSubview:_rootViewCoverViewForLeftView]; - } + if (_rootViewCoverViewForRightView) + [self.view insertSubview:_rootViewCoverViewForLeftView aboveSubview:_rootViewCoverViewForRightView]; + else + [self.view addSubview:_rootViewCoverViewForLeftView]; + } - // ----- + // ----- - __weak typeof(self) wself = self; + __weak typeof(self) wself = self; - _leftView = [[LGSideMenuView alloc] initWithLayoutSubviewsHandler:^(void) + _leftView = [[LGSideMenuView alloc] initWithLayoutSubviewsHandler:^(void) + { + if (wself) { - if (wself) - { - __strong typeof(wself) self = wself; - - CGSize size = self.view.frame.size; + __strong typeof(wself) self = wself; - if (kLGSideMenuSystemVersion < 8.0) - { - if (kLGSideMenuStatusBarOrientationIsPortrait) - size = CGSizeMake(MIN(size.width, size.height), MAX(size.width, size.height)); - else - size = CGSizeMake(MAX(size.width, size.height), MIN(size.width, size.height)); - } + CGSize size = self.view.frame.size; - [self leftViewWillLayoutSubviewsWithSize:CGSizeMake(_leftViewWidth, size.height)]; + if (kLGSideMenuSystemVersion < 8.0) + { + if (kLGSideMenuStatusBarOrientationIsPortrait) + size = CGSizeMake(MIN(size.width, size.height), MAX(size.width, size.height)); + else + size = CGSizeMake(MAX(size.width, size.height), MIN(size.width, size.height)); } - }]; - _leftView.backgroundColor = [UIColor clearColor]; - _leftView.hidden = YES; - if (_rootVC) - { - if (presentationStyle == LGSideMenuPresentationStyleSlideAbove) - [self.view addSubview:_leftView]; - else - [self.view insertSubview:_leftView belowSubview:_rootVC.view]; - } - // ----- + [self leftViewWillLayoutSubviewsWithSize:CGSizeMake(_leftViewWidth, size.height)]; + } + }]; + _leftView.backgroundColor = [UIColor clearColor]; + _leftView.hidden = YES; + if (_rootVC) + { + if (presentationStyle == LGSideMenuPresentationStyleSlideAbove) + [self.view addSubview:_leftView]; + else + [self.view insertSubview:_leftView belowSubview:_rootVC.view]; + } - _leftViewWidth = width; + // ----- - _leftViewPresentationStyle = presentationStyle; + _leftViewWidth = width; - _leftViewAlwaysVisibleOptions = alwaysVisibleOptions; + _leftViewPresentationStyle = presentationStyle; - // ----- + _leftViewAlwaysVisibleOptions = alwaysVisibleOptions; - if (presentationStyle != LGSideMenuPresentationStyleSlideAbove) - { - _leftViewCoverView = [UIView new]; - _leftViewCoverView.hidden = YES; - [self.view insertSubview:_leftViewCoverView aboveSubview:_leftView]; - } - else - { - _leftViewStyleView = [UIView new]; - _leftViewStyleView.hidden = YES; - _leftViewStyleView.layer.masksToBounds = NO; - _leftViewStyleView.layer.shadowOffset = CGSizeZero; - _leftViewStyleView.layer.shadowOpacity = 1.f; - _leftViewStyleView.layer.shouldRasterize = YES; - [self.view insertSubview:_leftViewStyleView belowSubview:_leftView]; - } + // ----- - // ----- + if (presentationStyle != LGSideMenuPresentationStyleSlideAbove) + { + _leftViewCoverView = [UIView new]; + _leftViewCoverView.hidden = YES; + [self.view insertSubview:_leftViewCoverView aboveSubview:_leftView]; + } + else + { + _leftViewStyleView = [UIView new]; + _leftViewStyleView.hidden = YES; + _leftViewStyleView.layer.masksToBounds = NO; + _leftViewStyleView.layer.shadowOffset = CGSizeZero; + _leftViewStyleView.layer.shadowOpacity = 1.f; + _leftViewStyleView.layer.shouldRasterize = YES; + [self.view insertSubview:_leftViewStyleView belowSubview:_leftView]; + } - [_rootViewStyleView removeFromSuperview]; - [self.view insertSubview:_rootViewStyleView belowSubview:_rootVC.view]; + // ----- - // ----- + [_rootViewStyleView removeFromSuperview]; + [self.view insertSubview:_rootViewStyleView belowSubview:_rootVC.view]; + + // ----- + if (!self.isUserRootViewScaleForLeftView) + { if (_leftViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove || _leftViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow) _rootViewScaleForLeftView = 1.f; else _rootViewScaleForLeftView = 0.8; + } - // ----- - - if (_leftViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) + if (_leftViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) + { + if (!self.isUserRootViewCoverColorForLeftView) _rootViewCoverColorForLeftView = kLGSideMenuCoverColor; - else + } + else + { + if (!self.isUserLeftViewCoverColor) _leftViewCoverColor = kLGSideMenuCoverColor; + } - // ----- - + if (!self.isUserLeftViewBackgroundImageInitialScale) + { if (_leftViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow || _leftViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) _leftViewBackgroundImageInitialScale = 1.f; else _leftViewBackgroundImageInitialScale = 1.4; + } - // ----- - + if (!self.isUserLeftViewInititialScale) + { if (_leftViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow || _leftViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) _leftViewInititialScale = 1.f; else if (_leftViewPresentationStyle == LGSideMenuPresentationStyleScaleFromBig) _leftViewInititialScale = 1.2; else _leftViewInititialScale = 0.8; + } - // ----- - + if (!self.isUserLeftViewInititialOffsetX) + { if (_leftViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow) _leftViewInititialOffsetX = -_leftViewWidth/2; + } - // ----- + // ----- - [self leftViewLayoutInvalidateWithPercentage:0.f]; - } - else NSLog(@"LGSideMenuController WARNING: Left view is already enabled"); + [self leftViewLayoutInvalidateWithPercentage:0.f]; } - (void)setRightViewEnabledWithWidth:(CGFloat)width presentationStyle:(LGSideMenuPresentationStyle)presentationStyle alwaysVisibleOptions:(LGSideMenuAlwaysVisibleOptions)alwaysVisibleOptions { - if (!_rightView) + NSAssert(_rightView == nil, @"Right view already exists"); + + _rootViewCoverViewForRightView = [UIView new]; + _rootViewCoverViewForRightView.hidden = YES; + if (_rootVC) { - _rootViewCoverViewForRightView = [UIView new]; - _rootViewCoverViewForRightView.hidden = YES; - if (_rootVC) - { - if (_rootViewCoverViewForLeftView) - [self.view insertSubview:_rootViewCoverViewForRightView aboveSubview:_rootViewCoverViewForLeftView]; - else - [self.view addSubview:_rootViewCoverViewForRightView]; - } + if (_rootViewCoverViewForLeftView) + [self.view insertSubview:_rootViewCoverViewForRightView aboveSubview:_rootViewCoverViewForLeftView]; + else + [self.view addSubview:_rootViewCoverViewForRightView]; + } - // ----- + // ----- - __weak typeof(self) wself = self; + __weak typeof(self) wself = self; - _rightView = [[LGSideMenuView alloc] initWithLayoutSubviewsHandler:^(void) + _rightView = [[LGSideMenuView alloc] initWithLayoutSubviewsHandler:^(void) + { + if (wself) { - if (wself) - { - __strong typeof(wself) self = wself; - - CGSize size = self.view.frame.size; + __strong typeof(wself) self = wself; - if (kLGSideMenuSystemVersion < 8.0) - { - if (kLGSideMenuStatusBarOrientationIsPortrait) - size = CGSizeMake(MIN(size.width, size.height), MAX(size.width, size.height)); - else - size = CGSizeMake(MAX(size.width, size.height), MIN(size.width, size.height)); - } + CGSize size = self.view.frame.size; - [self rightViewWillLayoutSubviewsWithSize:CGSizeMake(_rightViewWidth, size.height)]; + if (kLGSideMenuSystemVersion < 8.0) + { + if (kLGSideMenuStatusBarOrientationIsPortrait) + size = CGSizeMake(MIN(size.width, size.height), MAX(size.width, size.height)); + else + size = CGSizeMake(MAX(size.width, size.height), MIN(size.width, size.height)); } - }]; - _rightView.backgroundColor = [UIColor clearColor]; - _rightView.hidden = YES; - if (_rootVC) - { - if (presentationStyle == LGSideMenuPresentationStyleSlideAbove) - [self.view addSubview:_rightView]; - else - [self.view insertSubview:_rightView belowSubview:_rootVC.view]; - } - // ----- + [self rightViewWillLayoutSubviewsWithSize:CGSizeMake(_rightViewWidth, size.height)]; + } + }]; + _rightView.backgroundColor = [UIColor clearColor]; + _rightView.hidden = YES; + if (_rootVC) + { + if (presentationStyle == LGSideMenuPresentationStyleSlideAbove) + [self.view addSubview:_rightView]; + else + [self.view insertSubview:_rightView belowSubview:_rootVC.view]; + } - _rightViewWidth = width; + // ----- - _rightViewPresentationStyle = presentationStyle; + _rightViewWidth = width; - _rightViewAlwaysVisibleOptions = alwaysVisibleOptions; + _rightViewPresentationStyle = presentationStyle; - // ----- + _rightViewAlwaysVisibleOptions = alwaysVisibleOptions; - if (presentationStyle != LGSideMenuPresentationStyleSlideAbove) - { - _rightViewCoverView = [UIView new]; - _rightViewCoverView.hidden = YES; - [self.view insertSubview:_rightViewCoverView aboveSubview:_rightView]; - } - else - { - _rightViewStyleView = [UIView new]; - _rightViewStyleView.hidden = YES; - _rightViewStyleView.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.9]; - _rightViewStyleView.layer.masksToBounds = NO; - _rightViewStyleView.layer.borderWidth = 2.f; - _rightViewStyleView.layer.borderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f].CGColor; - _rightViewStyleView.layer.shadowColor = [UIColor colorWithWhite:0.f alpha:0.5].CGColor; - _rightViewStyleView.layer.shadowOffset = CGSizeZero; - _rightViewStyleView.layer.shadowOpacity = 1.f; - _rightViewStyleView.layer.shadowRadius = 5.f; - _rightViewStyleView.layer.shouldRasterize = YES; - [self.view insertSubview:_rightViewStyleView belowSubview:_rightView]; - } + // ----- - // ----- + if (presentationStyle != LGSideMenuPresentationStyleSlideAbove) + { + _rightViewCoverView = [UIView new]; + _rightViewCoverView.hidden = YES; + [self.view insertSubview:_rightViewCoverView aboveSubview:_rightView]; + } + else + { + _rightViewStyleView = [UIView new]; + _rightViewStyleView.hidden = YES; + _rightViewStyleView.backgroundColor = [UIColor colorWithWhite:0.3 alpha:0.9]; + _rightViewStyleView.layer.masksToBounds = NO; + _rightViewStyleView.layer.borderWidth = 2.f; + _rightViewStyleView.layer.borderColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f].CGColor; + _rightViewStyleView.layer.shadowColor = [UIColor colorWithWhite:0.f alpha:0.5].CGColor; + _rightViewStyleView.layer.shadowOffset = CGSizeZero; + _rightViewStyleView.layer.shadowOpacity = 1.f; + _rightViewStyleView.layer.shadowRadius = 5.f; + _rightViewStyleView.layer.shouldRasterize = YES; + [self.view insertSubview:_rightViewStyleView belowSubview:_rightView]; + } - [_rootViewStyleView removeFromSuperview]; - [self.view insertSubview:_rootViewStyleView belowSubview:_rootVC.view]; + // ----- - // ----- + [_rootViewStyleView removeFromSuperview]; + [self.view insertSubview:_rootViewStyleView belowSubview:_rootVC.view]; + // ----- + + if (!self.isUserRootViewScaleForRightView) + { if (_rightViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove || _rightViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow) _rootViewScaleForRightView = 1.f; else _rootViewScaleForRightView = 0.8; + } - // ----- - - if (_rightViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) + if (_rightViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) + { + if (!self.isUserRootViewCoverColorForRightView) _rootViewCoverColorForRightView = kLGSideMenuCoverColor; - else + } + else + { + if (!self.isUserRightViewCoverColor) _rightViewCoverColor = kLGSideMenuCoverColor; + } - // ----- - + if (!self.isUserRightViewBackgroundImageInitialScale) + { if (_rightViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow || _rightViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) _rightViewBackgroundImageInitialScale = 1.f; else _rightViewBackgroundImageInitialScale = 1.4; + } - // ----- - + if (!self.isUserRightViewInititialScale) + { if (_rightViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow || _rightViewPresentationStyle == LGSideMenuPresentationStyleSlideAbove) _rightViewInititialScale = 1.f; else if (_rightViewPresentationStyle == LGSideMenuPresentationStyleScaleFromBig) _rightViewInititialScale = 1.2; else _rightViewInititialScale = 0.8; + } - // ----- - + if (!self.isUserRightViewInititialOffsetX) + { if (_rightViewPresentationStyle == LGSideMenuPresentationStyleSlideBelow) _rightViewInititialOffsetX = _rightViewWidth/2; + } - // ----- + // ----- - [self rightViewLayoutInvalidateWithPercentage:0.f]; - } - else NSLog(@"LGSideMenuController WARNING: Right view is already enabled"); + [self rightViewLayoutInvalidateWithPercentage:0.f]; } #pragma mark - Show Hide @@ -1177,31 +1287,26 @@ - (void)showLeftViewPrepare { [self.view endEditing:YES]; + _leftViewShowing = YES; + // ----- - if (kLGSideMenuSystemVersion >= 7.0 && !self.isRightViewShowing) + if (kLGSideMenuSystemVersion >= 7.0) { - _savedStatusBarHidden = kLGSideMenuStatusBarHidden; + [_rootVC removeFromParentViewController]; - if (!kLGSideMenuStatusBarHidden && !kLGSideMenuIsLeftViewStatusBarVisible) - { - [_rootVC removeFromParentViewController]; + _currentShouldAutorotate = NO; + _currentPreferredStatusBarHidden = (kLGSideMenuStatusBarHidden || !kLGSideMenuIsLeftViewStatusBarVisible); + _currentPreferredStatusBarStyle = _leftViewStatusBarStyle; + _currentPreferredStatusBarUpdateAnimation = _leftViewStatusBarUpdateAnimation; -#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 - if (kLGSideMenuSystemVersion < 9.0) - [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; -#endif - _currentStatusBarHidden = YES; - [self setNeedsStatusBarAppearanceUpdate]; - } + [self statusBarAppearanceUpdate]; + [self setNeedsStatusBarAppearanceUpdate]; } // ----- [self leftViewLayoutInvalidateWithPercentage:0.f]; - - _leftViewShowing = YES; - [self colorsInvalidate]; [self hiddensInvalidate]; @@ -1210,7 +1315,8 @@ - (void)showLeftViewPrepare - (void)showLeftViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { - if (!kLGSideMenuIsLeftViewAlwaysVisible && !self.isLeftViewShowing) + if (!kLGSideMenuIsLeftViewAlwaysVisible && !self.isLeftViewShowing && + !(kLGSideMenuIsRightViewAlwaysVisible && _leftViewPresentationStyle != LGSideMenuPresentationStyleSlideAbove)) { [self showLeftViewPrepare]; @@ -1222,7 +1328,7 @@ - (void)showLeftViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage c { if (animated) { - [LGSideMenuController animateStandardWithDuration:0.5//*(1.f-percentage) + [LGSideMenuController animateStandardWithDuration:_leftViewAnimationSpeed animations:^(void) { [self rootViewLayoutInvalidateWithPercentage:1.f]; @@ -1251,21 +1357,6 @@ - (void)showLeftViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage c } } -- (void)hideLeftViewDone -{ - if (kLGSideMenuSystemVersion >= 7.0 && !_savedStatusBarHidden && kLGSideMenuStatusBarHidden && !self.isRightViewShowing) - { - [self addChildViewController:_rootVC]; - -#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 - if (kLGSideMenuSystemVersion < 9.0) - [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; -#endif - _currentStatusBarHidden = NO; - [self setNeedsStatusBarAppearanceUpdate]; - } -} - - (void)hideLeftViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { if (!kLGSideMenuIsLeftViewAlwaysVisible && self.isLeftViewShowing) @@ -1278,7 +1369,7 @@ - (void)hideLeftViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage c if (animated) { - [LGSideMenuController animateStandardWithDuration:0.5//*percentage + [LGSideMenuController animateStandardWithDuration:_leftViewAnimationSpeed animations:^(void) { [self rootViewLayoutInvalidateWithPercentage:0.f]; @@ -1286,10 +1377,10 @@ - (void)hideLeftViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage c } completion:^(BOOL finished) { - [self hideLeftViewDone]; - _leftViewShowing = NO; + [self hideLeftViewDone]; + if (finished) [self hiddensInvalidate]; @@ -1303,10 +1394,9 @@ - (void)hideLeftViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage c [self rootViewLayoutInvalidateWithPercentage:0.f]; [self leftViewLayoutInvalidateWithPercentage:0.f]; - [self hideLeftViewDone]; - _leftViewShowing = NO; + [self hideLeftViewDone]; [self hiddensInvalidate]; [[NSNotificationCenter defaultCenter] postNotificationName:kLGSideMenuControllerDidDismissLeftViewNotification object:self userInfo:nil]; @@ -1315,14 +1405,24 @@ - (void)hideLeftViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage c } } +- (void)hideLeftViewDone +{ + if (kLGSideMenuSystemVersion >= 7.0) + { + [self addChildViewController:_rootVC]; + + [self statusBarAppearanceUpdate]; + [self setNeedsStatusBarAppearanceUpdate]; + } +} + - (void)hideLeftViewComleteAfterGesture { [[NSNotificationCenter defaultCenter] postNotificationName:kLGSideMenuControllerWillDismissLeftViewNotification object:self userInfo:nil]; - - [self hideLeftViewDone]; _leftViewShowing = NO; + [self hideLeftViewDone]; [self hiddensInvalidate]; [[NSNotificationCenter defaultCenter] postNotificationName:kLGSideMenuControllerDidDismissLeftViewNotification object:self userInfo:nil]; @@ -1345,31 +1445,26 @@ - (void)showRightViewPrepare { [self.view endEditing:YES]; + _rightViewShowing = YES; + // ----- - if (kLGSideMenuSystemVersion >= 7.0 && !self.isLeftViewShowing) + if (kLGSideMenuSystemVersion >= 7.0) { - _savedStatusBarHidden = kLGSideMenuStatusBarHidden; + [_rootVC removeFromParentViewController]; - if (!kLGSideMenuStatusBarHidden && !kLGSideMenuIsRightViewStatusBarVisible) - { - [_rootVC removeFromParentViewController]; + _currentShouldAutorotate = NO; + _currentPreferredStatusBarHidden = (kLGSideMenuStatusBarHidden || !kLGSideMenuIsRightViewStatusBarVisible); + _currentPreferredStatusBarStyle = _rightViewStatusBarStyle; + _currentPreferredStatusBarUpdateAnimation = _rightViewStatusBarUpdateAnimation; -#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 - if (kLGSideMenuSystemVersion < 9.0) - [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; -#endif - _currentStatusBarHidden = YES; - [self setNeedsStatusBarAppearanceUpdate]; - } + [self statusBarAppearanceUpdate]; + [self setNeedsStatusBarAppearanceUpdate]; } // ----- [self rightViewLayoutInvalidateWithPercentage:0.f]; - - _rightViewShowing = YES; - [self colorsInvalidate]; [self hiddensInvalidate]; @@ -1378,7 +1473,8 @@ - (void)showRightViewPrepare - (void)showRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { - if (!kLGSideMenuIsRightViewAlwaysVisible && !self.isRightViewShowing) + if (!kLGSideMenuIsRightViewAlwaysVisible && !self.isRightViewShowing && + !(kLGSideMenuIsLeftViewAlwaysVisible && _rightViewPresentationStyle != LGSideMenuPresentationStyleSlideAbove)) { [self showRightViewPrepare]; @@ -1390,7 +1486,7 @@ - (void)showRightViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage { if (animated) { - [LGSideMenuController animateStandardWithDuration:0.5//*(1.f-percentage) + [LGSideMenuController animateStandardWithDuration:_rightViewAnimationSpeed animations:^(void) { [self rootViewLayoutInvalidateWithPercentage:1.f]; @@ -1419,21 +1515,6 @@ - (void)showRightViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage } } -- (void)hideRightViewDone -{ - if (kLGSideMenuSystemVersion >= 7.0 && !_savedStatusBarHidden && kLGSideMenuStatusBarHidden && !self.isLeftViewShowing) - { - [self addChildViewController:_rootVC]; - -#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0 - if (kLGSideMenuSystemVersion < 9.0) - [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; -#endif - _currentStatusBarHidden = NO; - [self setNeedsStatusBarAppearanceUpdate]; - } -} - - (void)hideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { if (!kLGSideMenuIsRightViewAlwaysVisible && self.isRightViewShowing) @@ -1446,7 +1527,7 @@ - (void)hideRightViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage if (animated) { - [LGSideMenuController animateStandardWithDuration:0.5//*percentage + [LGSideMenuController animateStandardWithDuration:_rightViewAnimationSpeed animations:^(void) { [self rootViewLayoutInvalidateWithPercentage:0.f]; @@ -1454,10 +1535,10 @@ - (void)hideRightViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage } completion:^(BOOL finished) { - [self hideRightViewDone]; - _rightViewShowing = NO; + [self hideRightViewDone]; + if (finished) [self hiddensInvalidate]; @@ -1471,10 +1552,9 @@ - (void)hideRightViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage [self rootViewLayoutInvalidateWithPercentage:0.f]; [self rightViewLayoutInvalidateWithPercentage:0.f]; - [self hideRightViewDone]; - _rightViewShowing = NO; + [self hideRightViewDone]; [self hiddensInvalidate]; [[NSNotificationCenter defaultCenter] postNotificationName:kLGSideMenuControllerDidDismissRightViewNotification object:self userInfo:nil]; @@ -1483,16 +1563,26 @@ - (void)hideRightViewAnimated:(BOOL)animated fromPercentage:(CGFloat)percentage } } +- (void)hideRightViewDone +{ + if (kLGSideMenuSystemVersion >= 7.0) + { + [self addChildViewController:_rootVC]; + + [self statusBarAppearanceUpdate]; + [self setNeedsStatusBarAppearanceUpdate]; + } +} + - (void)hideRightViewComleteAfterGesture { [[NSNotificationCenter defaultCenter] postNotificationName:kLGSideMenuControllerWillDismissRightViewNotification object:self userInfo:nil]; - [self hideRightViewDone]; + _rightViewShowing = NO; + [self hideRightViewDone]; [self hiddensInvalidate]; - _rightViewShowing = NO; - [[NSNotificationCenter defaultCenter] postNotificationName:kLGSideMenuControllerDidDismissRightViewNotification object:self userInfo:nil]; } @@ -1540,9 +1630,11 @@ - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer { CGFloat interactiveX = (self.isLeftViewShowing ? _leftViewWidth : 0.f); BOOL velocityDone = (self.isLeftViewShowing ? velocity.x < 0.f : velocity.x > 0.f); - CGFloat shift = (self.isLeftViewShowing ? 22.f : 44.f); - if (velocityDone && location.x >= interactiveX-44.f && location.x <= interactiveX+shift) + CGFloat shiftLeft = -44.f; + CGFloat shiftRight = (_swipeGestureArea == LGSideMenuSwipeGestureAreaBorders ? (self.isLeftViewShowing ? 22.f : 44.f) : _rootVC.view.bounds.size.width); + + if (velocityDone && location.x >= interactiveX+shiftLeft && location.x <= interactiveX+shiftRight) { _leftViewGestireStartX = [NSNumber numberWithFloat:location.x]; _leftViewShowingBeforeGesture = _leftViewShowing; @@ -1556,6 +1648,7 @@ - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer CGFloat firstVar = (self.isLeftViewShowingBeforeGesture ? location.x+(_leftViewWidth-_leftViewGestireStartX.floatValue) : location.x-_leftViewGestireStartX.floatValue); + CGFloat percentage = firstVar/_leftViewWidth; if (percentage < 0.f) percentage = 0.f; @@ -1590,9 +1683,11 @@ - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer { CGFloat interactiveX = (self.isRightViewShowing ? size.width-_rightViewWidth : size.width); BOOL velocityDone = (self.isRightViewShowing ? velocity.x > 0.f : velocity.x < 0.f); - CGFloat shift = (self.isRightViewShowing ? 22.f : 44.f); - if (velocityDone && location.x >= interactiveX-shift && location.x <= interactiveX+44.f) + CGFloat shiftLeft = (_swipeGestureArea == LGSideMenuSwipeGestureAreaBorders ? (self.isRightViewShowing ? 22.f : 44.f) : _rootVC.view.bounds.size.width); + CGFloat shiftRight = 44.f; + + if (velocityDone && location.x >= interactiveX-shiftLeft && location.x <= interactiveX+shiftRight) { _rightViewGestireStartX = [NSNumber numberWithFloat:location.x]; _rightViewShowingBeforeGesture = _rightViewShowing;