From d9b5847fdf1e7b04745a2addfdc7d6a1d589e05e Mon Sep 17 00:00:00 2001 From: Grigory Lutkov Date: Mon, 30 Nov 2015 14:36:07 +0300 Subject: [PATCH] Refactoring --- LGSideMenuController/LGSideMenuController.h | 6 +++--- LGSideMenuController/LGSideMenuController.m | 21 +++++++++------------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/LGSideMenuController/LGSideMenuController.h b/LGSideMenuController/LGSideMenuController.h index 000f8b9..765023a 100644 --- a/LGSideMenuController/LGSideMenuController.h +++ b/LGSideMenuController/LGSideMenuController.h @@ -227,6 +227,9 @@ typedef NS_ENUM(NSUInteger, LGSideMenuSwipeGestureArea) /** Default is 0.5 */ @property (assign, nonatomic) IBInspectable NSTimeInterval rightViewAnimationSpeed; +@property (assign, nonatomic) IBInspectable BOOL shouldShowLeftView; +@property (assign, nonatomic) IBInspectable BOOL shouldShowRightView; + - (instancetype)initWithRootViewController:(UIViewController *)rootViewController; - (UIView *)leftView; @@ -257,9 +260,6 @@ typedef NS_ENUM(NSUInteger, LGSideMenuSwipeGestureArea) - (void)hideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; - (void)showHideRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler; -- (BOOL)shouldShowLeftView; -- (BOOL)shouldShowRightView; - /** Unavailable, select it on your rootViewController */ - (BOOL)shouldAutorotate __attribute__((unavailable("select it on your rootViewController"))); /** Unavailable, select it on your rootViewController */ diff --git a/LGSideMenuController/LGSideMenuController.m b/LGSideMenuController/LGSideMenuController.m index 155366f..1768607 100644 --- a/LGSideMenuController/LGSideMenuController.m +++ b/LGSideMenuController/LGSideMenuController.m @@ -243,6 +243,11 @@ - (void)setupDefaults // ----- + _shouldShowLeftView = YES; + _shouldShowRightView = YES; + + // ----- + _backgroundImageViewForLeftView = [UIImageView new]; _backgroundImageViewForLeftView.hidden = YES; _backgroundImageViewForLeftView.contentMode = UIViewContentModeScaleAspectFill; @@ -540,14 +545,6 @@ - (void)setGesturesCancelsTouchesInView:(BOOL)gesturesCancelsTouchesInView _panGesture.cancelsTouchesInView = gesturesCancelsTouchesInView; } -- (BOOL)shouldShowLeftView { - return YES; -} - -- (BOOL)shouldShowRightView { - return YES; -} - #pragma mark - Layout Subviews - (void)leftViewWillLayoutSubviewsWithSize:(CGSize)size @@ -1323,7 +1320,7 @@ - (void)showLeftViewPrepare - (void)showLeftViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { - if (!kLGSideMenuIsLeftViewAlwaysVisible && !self.isLeftViewShowing && + if (!kLGSideMenuIsLeftViewAlwaysVisible && !self.isLeftViewShowing && self.shouldShowLeftView && !(kLGSideMenuIsRightViewAlwaysVisible && _leftViewPresentationStyle != LGSideMenuPresentationStyleSlideAbove)) { [self showLeftViewPrepare]; @@ -1481,7 +1478,7 @@ - (void)showRightViewPrepare - (void)showRightViewAnimated:(BOOL)animated completionHandler:(void(^)())completionHandler { - if (!kLGSideMenuIsRightViewAlwaysVisible && !self.isRightViewShowing && + if (!kLGSideMenuIsRightViewAlwaysVisible && !self.isRightViewShowing && self.shouldShowRightView && !(kLGSideMenuIsLeftViewAlwaysVisible && _rightViewPresentationStyle != LGSideMenuPresentationStyleSlideAbove)) { [self showRightViewPrepare]; @@ -1632,7 +1629,7 @@ - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer // ----- - if (_leftView && self.isLeftViewSwipeGestureEnabled && !kLGSideMenuIsLeftViewAlwaysVisible && !_rightViewGestireStartX && !self.isRightViewShowing && [self shouldShowLeftView]) + if (_leftView && self.isLeftViewSwipeGestureEnabled && !kLGSideMenuIsLeftViewAlwaysVisible && !_rightViewGestireStartX && !self.isRightViewShowing && self.shouldShowLeftView) { if (!_leftViewGestireStartX && (gestureRecognizer.state == UIGestureRecognizerStateBegan || gestureRecognizer.state == UIGestureRecognizerStateChanged)) { @@ -1685,7 +1682,7 @@ - (void)panGesture:(UIPanGestureRecognizer *)gestureRecognizer // ----- - if (_rightView && self.isRightViewSwipeGestureEnabled && !kLGSideMenuIsRightViewAlwaysVisible && !_leftViewGestireStartX && !self.isLeftViewShowing && [self shouldShowRightView]) + if (_rightView && self.isRightViewSwipeGestureEnabled && !kLGSideMenuIsRightViewAlwaysVisible && !_leftViewGestireStartX && !self.isLeftViewShowing && self.shouldShowRightView) { if (!_rightViewGestireStartX && (gestureRecognizer.state == UIGestureRecognizerStateBegan || gestureRecognizer.state == UIGestureRecognizerStateChanged)) {