diff --git a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m index f71646e..b2c7b1b 100644 --- a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m +++ b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m @@ -63,6 +63,8 @@ - (void)viewWillAppear:(BOOL)animated _plusButtonsViewMain.coverColor = [UIColor colorWithWhite:1.f alpha:0.7]; _plusButtonsViewMain.position = LGPlusButtonsViewPositionBottomRight; _plusButtonsViewMain.plusButtonAnimationType = LGPlusButtonAnimationTypeRotate; + _plusButtonsViewMain.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical; + _plusButtonsViewMain.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical; [_plusButtonsViewMain setButtonsTitles:@[@"+", @"", @"", @""] forState:UIControlStateNormal]; [_plusButtonsViewMain setDescriptionsTexts:@[@"", @"Take a photo", @"Choose from gallery", @"Send a message"]]; @@ -116,79 +118,79 @@ - (void)viewWillAppear:(BOOL)animated [self.navigationController.view addSubview:_plusButtonsViewMain]; - // ----- - - _plusButtonsViewNavBar = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:3 - firstButtonIsPlusButton:NO - showAfterInit:NO - actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) - { - NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); - }]; - - _plusButtonsViewNavBar.showHideOnScroll = NO; - _plusButtonsViewNavBar.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop; - _plusButtonsViewNavBar.position = LGPlusButtonsViewPositionTopRight; - - [_plusButtonsViewNavBar setButtonsTitles:@[@"1", @"2", @"3"] forState:UIControlStateNormal]; - [_plusButtonsViewNavBar setDescriptionsTexts:@[@"Description 1", @"Description 2", @"Description 3"]]; - - [_plusButtonsViewNavBar setButtonsTitleFont:[UIFont boldSystemFontOfSize:32.f] forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewNavBar setButtonsSize:CGSizeMake(52.f, 52.f) forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewNavBar setButtonsLayerCornerRadius:52.f/2.f forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewNavBar setButtonsBackgroundColor:[UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f] forState:UIControlStateNormal]; - [_plusButtonsViewNavBar setButtonsBackgroundColor:[UIColor colorWithRed:0.2 green:0.6 blue:1.f alpha:1.f] forState:UIControlStateHighlighted]; - [_plusButtonsViewNavBar setButtonsLayerShadowColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.f]]; - [_plusButtonsViewNavBar setButtonsLayerShadowOpacity:0.5]; - [_plusButtonsViewNavBar setButtonsLayerShadowRadius:3.f]; - [_plusButtonsViewNavBar setButtonsLayerShadowOffset:CGSizeMake(0.f, 2.f)]; - - [_plusButtonsViewNavBar setDescriptionsTextColor:[UIColor whiteColor]]; - [_plusButtonsViewNavBar setDescriptionsBackgroundColor:[UIColor colorWithWhite:0.f alpha:0.66]]; - [_plusButtonsViewNavBar setDescriptionsLayerCornerRadius:6.f forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewNavBar setDescriptionsContentEdgeInsets:UIEdgeInsetsMake(4.f, 8.f, 4.f, 8.f) forOrientation:LGPlusButtonsViewOrientationAll]; - - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) - { - [_plusButtonsViewNavBar setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationLandscape]; - [_plusButtonsViewNavBar setButtonsLayerCornerRadius:44.f/2.f forOrientation:LGPlusButtonsViewOrientationLandscape]; - [_plusButtonsViewNavBar setButtonsTitleFont:[UIFont systemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationLandscape]; - } - - [self.scrollView addSubview:_plusButtonsViewNavBar]; - - // ----- - - _plusButtonsViewExample = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:3 - firstButtonIsPlusButton:YES - showAfterInit:YES - actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) - { - NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); - }]; - - _plusButtonsViewExample.position = LGPlusButtonsViewPositionBottomLeft; - _plusButtonsViewExample.plusButtonAnimationType = LGPlusButtonAnimationTypeCrossDissolve; - _plusButtonsViewExample.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolve; - - [_plusButtonsViewExample setButtonsTitles:@[@"+", @"1", @"2"] forState:UIControlStateNormal]; - [_plusButtonsViewExample setDescriptionsTexts:@[@"", @"Description 1", @"Description 2"]]; - - [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.f blue:0.5 alpha:1.f] forState:UIControlStateNormal]; - [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted]; - [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted|UIControlStateSelected]; - [_plusButtonsViewExample setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewExample setButtonsLayerBorderWidth:2.f]; - [_plusButtonsViewExample setButtonsLayerBorderColor:[UIColor colorWithWhite:0.9 alpha:1.f]]; - [_plusButtonsViewExample setButtonsTitleFont:[UIFont systemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewExample setButtonAtIndex:0 titleOffset:CGPointMake(0.f, -2.f) forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewExample setButtonAtIndex:0 title:@"-" forState:UIControlStateSelected]; - - [_plusButtonsViewExample setDescriptionsTextColor:[UIColor whiteColor]]; - [_plusButtonsViewExample setDescriptionsFont:[UIFont boldSystemFontOfSize:18.f] forOrientation:LGPlusButtonsViewOrientationAll]; - [_plusButtonsViewExample setDescriptionsInsets:UIEdgeInsetsMake(0.f, 0.f, 0.f, 4.f) forOrientation:LGPlusButtonsViewOrientationAll]; - - [_exampleView addSubview:_plusButtonsViewExample]; +// // ----- +// +// _plusButtonsViewNavBar = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:3 +// firstButtonIsPlusButton:NO +// showAfterInit:NO +// actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) +// { +// NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); +// }]; +// +// _plusButtonsViewNavBar.showHideOnScroll = NO; +// _plusButtonsViewNavBar.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop; +// _plusButtonsViewNavBar.position = LGPlusButtonsViewPositionTopRight; +// +// [_plusButtonsViewNavBar setButtonsTitles:@[@"1", @"2", @"3"] forState:UIControlStateNormal]; +// [_plusButtonsViewNavBar setDescriptionsTexts:@[@"Description 1", @"Description 2", @"Description 3"]]; +// +// [_plusButtonsViewNavBar setButtonsTitleFont:[UIFont boldSystemFontOfSize:32.f] forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewNavBar setButtonsSize:CGSizeMake(52.f, 52.f) forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewNavBar setButtonsLayerCornerRadius:52.f/2.f forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewNavBar setButtonsBackgroundColor:[UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f] forState:UIControlStateNormal]; +// [_plusButtonsViewNavBar setButtonsBackgroundColor:[UIColor colorWithRed:0.2 green:0.6 blue:1.f alpha:1.f] forState:UIControlStateHighlighted]; +// [_plusButtonsViewNavBar setButtonsLayerShadowColor:[UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.f]]; +// [_plusButtonsViewNavBar setButtonsLayerShadowOpacity:0.5]; +// [_plusButtonsViewNavBar setButtonsLayerShadowRadius:3.f]; +// [_plusButtonsViewNavBar setButtonsLayerShadowOffset:CGSizeMake(0.f, 2.f)]; +// +// [_plusButtonsViewNavBar setDescriptionsTextColor:[UIColor whiteColor]]; +// [_plusButtonsViewNavBar setDescriptionsBackgroundColor:[UIColor colorWithWhite:0.f alpha:0.66]]; +// [_plusButtonsViewNavBar setDescriptionsLayerCornerRadius:6.f forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewNavBar setDescriptionsContentEdgeInsets:UIEdgeInsetsMake(4.f, 8.f, 4.f, 8.f) forOrientation:LGPlusButtonsViewOrientationAll]; +// +// if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) +// { +// [_plusButtonsViewNavBar setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationLandscape]; +// [_plusButtonsViewNavBar setButtonsLayerCornerRadius:44.f/2.f forOrientation:LGPlusButtonsViewOrientationLandscape]; +// [_plusButtonsViewNavBar setButtonsTitleFont:[UIFont systemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationLandscape]; +// } +// +// [self.scrollView addSubview:_plusButtonsViewNavBar]; +// +// // ----- +// +// _plusButtonsViewExample = [LGPlusButtonsView plusButtonsViewWithNumberOfButtons:3 +// firstButtonIsPlusButton:YES +// showAfterInit:YES +// actionHandler:^(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index) +// { +// NSLog(@"actionHandler | title: %@, description: %@, index: %lu", title, description, (long unsigned)index); +// }]; +// +// _plusButtonsViewExample.position = LGPlusButtonsViewPositionBottomLeft; +// _plusButtonsViewExample.plusButtonAnimationType = LGPlusButtonAnimationTypeCrossDissolve; +// _plusButtonsViewExample.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolve; +// +// [_plusButtonsViewExample setButtonsTitles:@[@"+", @"1", @"2"] forState:UIControlStateNormal]; +// [_plusButtonsViewExample setDescriptionsTexts:@[@"", @"Description 1", @"Description 2"]]; +// +// [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.f blue:0.5 alpha:1.f] forState:UIControlStateNormal]; +// [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted]; +// [_plusButtonsViewExample setButtonsBackgroundColor:[UIColor colorWithRed:1.f green:0.2 blue:0.6 alpha:1.f] forState:UIControlStateHighlighted|UIControlStateSelected]; +// [_plusButtonsViewExample setButtonsSize:CGSizeMake(44.f, 44.f) forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewExample setButtonsLayerBorderWidth:2.f]; +// [_plusButtonsViewExample setButtonsLayerBorderColor:[UIColor colorWithWhite:0.9 alpha:1.f]]; +// [_plusButtonsViewExample setButtonsTitleFont:[UIFont systemFontOfSize:24.f] forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewExample setButtonAtIndex:0 titleOffset:CGPointMake(0.f, -2.f) forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewExample setButtonAtIndex:0 title:@"-" forState:UIControlStateSelected]; +// +// [_plusButtonsViewExample setDescriptionsTextColor:[UIColor whiteColor]]; +// [_plusButtonsViewExample setDescriptionsFont:[UIFont boldSystemFontOfSize:18.f] forOrientation:LGPlusButtonsViewOrientationAll]; +// [_plusButtonsViewExample setDescriptionsInsets:UIEdgeInsetsMake(0.f, 0.f, 0.f, 4.f) forOrientation:LGPlusButtonsViewOrientationAll]; +// +// [_exampleView addSubview:_plusButtonsViewExample]; } #pragma mark - Dealloc diff --git a/LGPlusButtonsView.podspec b/LGPlusButtonsView.podspec index c92a2ca..f3ecb7d 100644 --- a/LGPlusButtonsView.podspec +++ b/LGPlusButtonsView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'LGPlusButtonsView' - s.version = '1.1.1' + s.version = '1.1.7' s.platform = :ios, '6.0' s.license = 'MIT' s.homepage = 'https://github.com/Friend-LGA/LGPlusButtonsView' diff --git a/LGPlusButtonsView/LGPlusButtonsView.h b/LGPlusButtonsView/LGPlusButtonsView.h index 61521c6..39839ca 100644 --- a/LGPlusButtonsView/LGPlusButtonsView.h +++ b/LGPlusButtonsView/LGPlusButtonsView.h @@ -55,6 +55,7 @@ static NSString *const kLGPlusButtonsViewActionNotification = @"kLGPlus - (void)plusButtonsViewDidShowButtons:(LGPlusButtonsView *)plusButtonsView; - (void)plusButtonsViewDidHideButtons:(LGPlusButtonsView *)plusButtonsView; - (void)plusButtonsView:(LGPlusButtonsView *)plusButtonsView buttonPressedWithTitle:(NSString *)title description:(NSString *)description index:(NSUInteger)index; +- (void)plusButtonsView:(LGPlusButtonsView *)plusButtonsView buttonTouchDownWithTitle:(NSString *)title description:(NSString *)description index:(NSUInteger)index; @end @@ -85,7 +86,8 @@ typedef NS_ENUM(NSUInteger, LGPlusButtonsAppearingAnimationType) LGPlusButtonsAppearingAnimationTypeCrossDissolve = 1, LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal = 2, LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical = 3, - LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop = 4 + LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop = 4, + LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical = 5 }; typedef NS_ENUM(NSUInteger, LGPlusButtonAnimationType) @@ -97,7 +99,7 @@ typedef NS_ENUM(NSUInteger, LGPlusButtonAnimationType) @property (assign, nonatomic, readonly, getter=isShowing) BOOL showing; @property (assign, nonatomic, readonly, getter=isButtonsShowing) BOOL buttonsShowing; -@property (assign, nonatomic, getter=isShowHideOnScroll) BOOL showHideOnScroll; +@property (assign, nonatomic) BOOL isShowHideOnScroll; /** Hide additional buttons on scroll. Default is NO */ @property (assign, nonatomic, getter=isHideButtonsOnScroll) BOOL hideButtonsOnScroll; /** Default is YES */ @@ -150,6 +152,8 @@ typedef NS_ENUM(NSUInteger, LGPlusButtonAnimationType) #pragma mark - Buttons all +- (CGRect)buttonFrame:(NSUInteger)index; + - (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state; - (void)setButtonsTitleColor:(UIColor *)titleColor forState:(UIControlState)state; - (void)setButtonsTitleColors:(NSArray *)titleColors forState:(UIControlState)state; diff --git a/LGPlusButtonsView/LGPlusButtonsView.m b/LGPlusButtonsView/LGPlusButtonsView.m index 2f76fc2..7c12e67 100644 --- a/LGPlusButtonsView/LGPlusButtonsView.m +++ b/LGPlusButtonsView/LGPlusButtonsView.m @@ -72,9 +72,6 @@ typedef NS_ENUM(NSUInteger, LGPlusButtonDescriptionsPosition) LGPlusButtonDescriptionsPositionRight = 1 }; -@property (assign, nonatomic, getter=isObserversAdded) BOOL observersAdded; -@property (assign, nonatomic, getter=isObserversForScrollViewAdded) BOOL observersForScrollViewAdded; - @property (assign, nonatomic) LGPlusButtonDescriptionsPosition descriptionsPosition; @property (assign, nonatomic) UIView *parentView; @@ -119,7 +116,7 @@ - (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons _appearingAnimationSpeed = 0.3; _buttonsAppearingAnimationSpeed = 0.3; _hideAnimationCoef = 0.66; - _showHideOnScroll = YES; + self.isShowHideOnScroll = YES; _disableShowHideOnScrollIfContentSizeLessThenFrame = YES; // ----- @@ -158,6 +155,22 @@ - (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]; [_coverView addGestureRecognizer:tapGesture]; + + UISwipeGestureRecognizer *slideRightGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]; + slideRightGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; + [_coverView addGestureRecognizer:slideRightGestureRecognizer]; + + UISwipeGestureRecognizer *slideLeftGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]; + slideLeftGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; + [_coverView addGestureRecognizer:slideLeftGestureRecognizer]; + + UISwipeGestureRecognizer *slideUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]; + slideUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp; + [_coverView addGestureRecognizer:slideUpGestureRecognizer]; + + UISwipeGestureRecognizer *slideDownGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]; + slideDownGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown; + [_coverView addGestureRecognizer:slideDownGestureRecognizer]; // ----- @@ -190,6 +203,7 @@ - (instancetype)initWithNumberOfButtons:(NSUInteger)numberOfButtons LGPlusButton *button = [LGPlusButton new]; button.tag = i; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; + [button addTarget:self action:@selector(buttonTouchDownAction:) forControlEvents:UIControlEventTouchDown]; if (showAfterInit) button.showing = ((firstButtonIsPlusButton && i == 0) || !firstButtonIsPlusButton); [wrapperView2 addSubview:button]; @@ -300,6 +314,9 @@ + (instancetype)plusButtonsViewWithNumberOfButtons:(NSUInteger)numberOfButtons - (void)dealloc { + [self removeObservers:self.superview]; + [self setObservedScrollView:nil]; + #if DEBUG NSLog(@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__); #endif @@ -313,8 +330,16 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event UIView *view = nil; - for (LGPlusButton *button in _buttonsArray) + for (NSUInteger i=0; i<_buttonsArray.count; i++) { + LGPlusButton *button = _buttonsArray[i]; + WrapperView *buttonWrapperView = _buttonWrapperViewsArray1[i]; + + // don't process event if button is hidden. + if (buttonWrapperView.alpha == 0.) { + continue; + } + CGPoint newPoint = [self convertPoint:point toView:button]; view = [button hitTest:newPoint withEvent:event]; @@ -336,10 +361,8 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event - (void)willMoveToSuperview:(UIView *)newSuperview { [self removeObservers:self.superview]; - - if (newSuperview) - [self addObservers:newSuperview]; - + [self addObservers:newSuperview]; + [super willMoveToSuperview:newSuperview]; } @@ -376,6 +399,17 @@ - (UIEdgeInsets)contentEdgeInsetsForOrientation:(LGPlusButtonsViewOrientation)or #pragma mark Buttons all +- (CGRect)buttonFrame:(NSUInteger)index { + UIView *button = _buttonsArray[ index ]; + if (button == nil) { + NSAssert(NO, @"Unexpected button index: %@, buttons count: %@", @(index), @(_buttonsArray.count)); + return CGRectZero; + } + + CGRect frame = [self convertRect:button.bounds fromView:button]; + return frame; +} + - (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state { NSAssert(_buttonsArray.count == titles.count, kLGPlusButtonsViewAssertionWarning(@"titles")); @@ -1258,6 +1292,16 @@ - (void)tapGesture:(UITapGestureRecognizer *)gestureRecognizer [self hideAnimated:YES completionHandler:nil]; } +- (void)buttonTouchDownAction:(LGPlusButton *)button +{ + NSUInteger index = button.tag; + + LGPlusButtonDescription *description = _descriptionsArray[index]; + + if (_delegate && [_delegate respondsToSelector:@selector(plusButtonsView:buttonTouchDownWithTitle:description:index:)]) + [_delegate plusButtonsView:self buttonTouchDownWithTitle:button.titleLabel.text description:description.text index:button.tag]; +} + - (void)buttonAction:(LGPlusButton *)button { NSUInteger index = button.tag; @@ -1574,10 +1618,11 @@ - (void)showCoverViewAnimated:(BOOL)animated [LGPlusButtonsView animateStandardWithDuration:duration delay:0.f + animationType:type animations:^(void) - { - _coverView.alpha = 1.f; - } + { + _coverView.alpha = 1.f; + } completion:nil]; } } @@ -1607,26 +1652,41 @@ - (void)hideCoverViewAnimated:(BOOL)animated [LGPlusButtonsView animateStandardWithDuration:duration delay:0.f + animationType:type animations:^(void) - { - _coverView.alpha = 0.f; - } + { + _coverView.alpha = 0.f; + } completion:^(BOOL finished) - { - if (finished) - { - _coverView.hidden = YES; - - if ([self.superview isKindOfClass:[UIScrollView class]]) - [(UIScrollView *)self.superview setScrollEnabled:YES]; - } - }]; + { + if (finished) + { + _coverView.hidden = YES; + + if ([self.superview isKindOfClass:[UIScrollView class]]) + [(UIScrollView *)self.superview setScrollEnabled:YES]; + } + }]; } } } #pragma mark - Button Animations + +- (CGFloat)buttonStartOffset:(NSUInteger)index { + LGPlusButtonsViewOrientation orientation = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? LGPlusButtonsViewOrientationPortrait : LGPlusButtonsViewOrientationLandscape; + CGFloat offset = 0; + for (NSUInteger i = 0; i < index; i++) { + WrapperView *buttonWrapper = _buttonWrapperViewsArray1[i]; + LGPlusButton *button = _buttonsArray[i]; + UIEdgeInsets buttonInsets = [button insetsForOrientation:orientation]; + offset += buttonWrapper.frame.size.height + buttonInsets.top + buttonInsets.bottom; + } + return offset; +} + + - (void)showButtonAtIndex:(NSUInteger)index animationType:(LGPlusButtonsAppearingAnimationType)type delay:(NSTimeInterval)delay @@ -1649,10 +1709,17 @@ - (void)showButtonAtIndex:(NSUInteger)index if (scaleX && scaleY) transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(scaleX, scaleY)); } + if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical) + { + CGFloat ty = [self buttonStartOffset:index]; + transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation([[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.x"] floatValue], + ty)); + } else { transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation([[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.x"] floatValue], [[(CALayer *)buttonWrapperView1.layer.presentationLayer valueForKeyPath:@"transform.translation.y"] floatValue])); + } buttonWrapperView1.alpha = [(CALayer *)buttonWrapperView1.layer.presentationLayer opacity]; @@ -1676,19 +1743,26 @@ - (void)showButtonAtIndex:(NSUInteger)index } else { - CGFloat dif = 1.f-buttonWrapperView1.alpha; - NSTimeInterval duration = animationSpeed*dif; - + CGFloat dif; + NSTimeInterval duration; + if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical) { + duration = (0.2 + index * 0.05); + delay = 0; + } else { + dif = 1.f-buttonWrapperView1.alpha; + duration = animationSpeed*dif; + } [LGPlusButtonsView animateStandardWithDuration:duration delay:delay + animationType:type animations:^(void) - { - [self showAnimationsWithButtonAtIndex:index]; - } + { + [self showAnimationsWithButtonAtIndex:index]; + } completion:^(BOOL finished) - { - if (completionHandler) completionHandler(finished); - }]; + { + if (completionHandler) completionHandler(finished); + }]; } } @@ -1760,9 +1834,15 @@ - (void)hideButtonAtIndex:(NSUInteger)index { if (animated) { - CGFloat dif = buttonWrapperView1.alpha-0.f; - NSTimeInterval duration = animationSpeed*dif*_hideAnimationCoef; - + CGFloat dif; + NSTimeInterval duration; + if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical) { + duration = 0.2 + index * 0.05; + delay = 0; + } else { + dif = buttonWrapperView1.alpha-0.f; + duration = animationSpeed*dif*_hideAnimationCoef; + } [UIView animateWithDuration:duration delay:delay options:0 @@ -1818,6 +1898,13 @@ - (void)hideAnimationsWithButtonAtIndex:(NSUInteger)index else transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(0.f, -buttonWrapperView1.frame.size.height)); } + else if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical) { + CGFloat ty = [self buttonStartOffset:index]; + if (_position == LGPlusButtonsViewPositionTopLeft || _position == LGPlusButtonsViewPositionTopRight) { + ty = -ty; + } + transform = CGAffineTransformConcat(transform, CGAffineTransformMakeTranslation(0.f, ty)); + } else if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop) { transform = CGAffineTransformConcat(transform, CGAffineTransformMakeScale(0.5, 0.5)); @@ -1907,58 +1994,42 @@ - (void)deselectPlusButtonViewWithAnimationType:(LGPlusButtonAnimationType)type - (void)addObservers:(UIView *)view { - if (!self.isObserversAdded && view) - { - _observersAdded = YES; - - [view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil]; - - if ([view isKindOfClass:[UIScrollView class]]) - { - [view addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; - [view addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; - [view addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; - } - - if (_observedScrollView) - { - NSAssert([_observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); - - _observersForScrollViewAdded = YES; + if (!view) return; + + [view addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil]; + + if ([view isKindOfClass:[UIScrollView class]]) + [self setObservedScrollView:view]; +} - [_observedScrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; - [_observedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; - [_observedScrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; - } - } +- (void)addScrollViewObservers:(UIScrollView *)observedScrollView +{ + if (!observedScrollView) return; + + NSAssert([observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); + + [observedScrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; + [observedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; + [observedScrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; } - (void)removeObservers:(UIView *)view { - if (self.isObserversAdded && view) - { - _observersAdded = NO; - - [view removeObserver:self forKeyPath:@"frame"]; - - if ([view isKindOfClass:[UIScrollView class]]) - { - [view removeObserver:self forKeyPath:@"contentInset"]; - [view removeObserver:self forKeyPath:@"contentOffset"]; - [view removeObserver:self forKeyPath:@"contentSize"]; - } - - if (self.isObserversForScrollViewAdded) - { - NSAssert([_observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); - - _observersForScrollViewAdded = NO; + if (!view) return; + + [view removeObserver:self forKeyPath:@"frame"]; + + if (view == self.observedScrollView) + [self setObservedScrollView:nil]; +} - [_observedScrollView removeObserver:self forKeyPath:@"contentInset"]; - [_observedScrollView removeObserver:self forKeyPath:@"contentOffset"]; - [_observedScrollView removeObserver:self forKeyPath:@"contentSize"]; - } - } +- (void)removeScrollViewObservers:(UIScrollView *)observedScrollView +{ + if (!observedScrollView) return; + + [observedScrollView removeObserver:self forKeyPath:@"contentInset"]; + [observedScrollView removeObserver:self forKeyPath:@"contentOffset"]; + [observedScrollView removeObserver:self forKeyPath:@"contentSize"]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -2025,42 +2096,35 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N - (void)setObservedScrollView:(UIScrollView *)observedScrollView { - if (observedScrollView) - NSAssert([observedScrollView isKindOfClass:[UIScrollView class]], @"observedScrollView needs to have UIScrollView kind of class"); - - if (self.isObserversForScrollViewAdded) - { - [_observedScrollView removeObserver:self forKeyPath:@"contentInset"]; - [_observedScrollView removeObserver:self forKeyPath:@"contentOffset"]; - [_observedScrollView removeObserver:self forKeyPath:@"contentSize"]; - } - - if (observedScrollView) - { - _observersForScrollViewAdded = YES; - - [observedScrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:nil]; - [observedScrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil]; - [observedScrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; - } - else _observersForScrollViewAdded = NO; + [self removeScrollViewObservers:self.observedScrollView]; + [self addScrollViewObservers:observedScrollView]; _observedScrollView = observedScrollView; } #pragma mark - Support -+ (void)animateStandardWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay animations:(void(^)())animations completion:(void(^)(BOOL finished))completion ++ (void)animateStandardWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay animationType:(LGPlusButtonsAppearingAnimationType)type animations:(void(^)())animations completion:(void(^)(BOOL finished))completion { - if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) + if (@available(iOS 7.0, *)) { - [UIView animateWithDuration:duration - delay:delay - usingSpringWithDamping:1.f - initialSpringVelocity:0.5 - options:0 - animations:animations - completion:completion]; + if (type == LGPlusButtonsAppearingAnimationTypeCrossDissolveAndFullySlideVertical) { + [UIView animateWithDuration:duration + delay:0 + usingSpringWithDamping:0.6f + initialSpringVelocity:0. + options:0 + animations:animations + completion:completion]; + } else { + [UIView animateWithDuration:duration + delay:delay + usingSpringWithDamping:1.f + initialSpringVelocity:0.5 + options:0 + animations:animations + completion:completion]; + } } else {