diff --git a/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj b/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj index b70915a..7a3f639 100644 --- a/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj +++ b/Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1946D2D8D0CE8124E0632DEA /* libPods-LGPlusButtonsViewDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 23A4E5C49FE8BEAB57D05B49 /* libPods-LGPlusButtonsViewDemo.a */; }; + 4A1F8E611BEE098100D0B57E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */; }; 4A3F4B5A1AA8BA51006D9DAA /* PlusViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */; }; 847A899A1A9F298B004A8413 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A89971A9F298B004A8413 /* NavigationController.m */; }; 847A899B1A9F298B004A8413 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A89991A9F298B004A8413 /* TableViewController.m */; }; @@ -19,6 +20,7 @@ /* Begin PBXFileReference section */ 23A4E5C49FE8BEAB57D05B49 /* libPods-LGPlusButtonsViewDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LGPlusButtonsViewDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 4A3F4B581AA8BA51006D9DAA /* PlusViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusViewController.h; sourceTree = ""; }; 4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlusViewController.m; sourceTree = ""; }; 6CA3D88515E7F3B71D89BE22 /* Pods-LGPlusButtonsViewDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LGPlusButtonsViewDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LGPlusButtonsViewDemo/Pods-LGPlusButtonsViewDemo.release.xcconfig"; sourceTree = ""; }; @@ -123,6 +125,7 @@ 4A3F4B5C1AA8BDAD006D9DAA /* Demo View Controllers */, 84C5B7D71A9F22C800EEEB24 /* Images.xcassets */, 84C5B7CA1A9F22C800EEEB24 /* Supporting Files */, + 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */, ); path = LGPlusButtonsViewDemo; sourceTree = ""; @@ -197,6 +200,7 @@ buildActionMask = 2147483647; files = ( 84C5B7D81A9F22C800EEEB24 /* Images.xcassets in Resources */, + 4A1F8E611BEE098100D0B57E /* LaunchScreen.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Demo/LGPlusButtonsViewDemo/AppDelegate.h b/Demo/LGPlusButtonsViewDemo/AppDelegate.h index e87c1fb..fa09f43 100644 --- a/Demo/LGPlusButtonsViewDemo/AppDelegate.h +++ b/Demo/LGPlusButtonsViewDemo/AppDelegate.h @@ -7,11 +7,9 @@ // #import -#import "NavigationController.h" @interface AppDelegate : UIResponder @property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) UINavigationController *navigationController; @end diff --git a/Demo/LGPlusButtonsViewDemo/AppDelegate.m b/Demo/LGPlusButtonsViewDemo/AppDelegate.m index 173eef7..8ab40db 100644 --- a/Demo/LGPlusButtonsViewDemo/AppDelegate.m +++ b/Demo/LGPlusButtonsViewDemo/AppDelegate.m @@ -7,18 +7,21 @@ // #import "AppDelegate.h" +#import "NavigationController.h" +#import "TableViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.navigationController = [NavigationController new]; - + TableViewController *tableViewController = [TableViewController new]; + NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:tableViewController]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.rootViewController = self.navigationController; + self.window.rootViewController = navigationController; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; - + return YES; } diff --git a/Demo/LGPlusButtonsViewDemo/Info.plist b/Demo/LGPlusButtonsViewDemo/Info.plist index 7c961f8..eabb3ae 100644 --- a/Demo/LGPlusButtonsViewDemo/Info.plist +++ b/Demo/LGPlusButtonsViewDemo/Info.plist @@ -22,6 +22,8 @@ 1 LSRequiresIPhoneOS + UILaunchStoryboardName + LaunchScreen UIRequiredDeviceCapabilities armv7 diff --git a/Demo/LGPlusButtonsViewDemo/LaunchScreen.storyboard b/Demo/LGPlusButtonsViewDemo/LaunchScreen.storyboard new file mode 100644 index 0000000..ad9c6f4 --- /dev/null +++ b/Demo/LGPlusButtonsViewDemo/LaunchScreen.storyboard @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/LGPlusButtonsViewDemo/NavigationController.m b/Demo/LGPlusButtonsViewDemo/NavigationController.m index 1fe1b20..6b505ef 100644 --- a/Demo/LGPlusButtonsViewDemo/NavigationController.m +++ b/Demo/LGPlusButtonsViewDemo/NavigationController.m @@ -7,30 +7,36 @@ // #import "NavigationController.h" -#import "TableViewController.h" @interface NavigationController () -@property (strong, nonatomic) TableViewController *tableViewController; - @end @implementation NavigationController -- (id)init +- (void)viewDidLoad { - self = [super init]; - if (self) - { - self.tableViewController = [TableViewController new]; - [self setViewControllers:@[self.tableViewController]]; - } - return self; + [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.75]; } - (BOOL)shouldAutorotate { - return self.topViewController.shouldAutorotate; + return YES; +} + +- (BOOL)prefersStatusBarHidden +{ + return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation); +} + +- (UIStatusBarStyle)preferredStatusBarStyle +{ + return UIStatusBarStyleLightContent; } @end diff --git a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m index 1ab9b4e..75d4d47 100644 --- a/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m +++ b/Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m @@ -26,19 +26,19 @@ - (id)initWithTitle:(NSString *)title if (self) { self.title = title; - + // ----- - + _scrollView = [UIScrollView new]; _scrollView.backgroundColor = [UIColor whiteColor]; _scrollView.alwaysBounceVertical = YES; [self.view addSubview:_scrollView]; - + _textLabel = [UILabel new]; _textLabel.backgroundColor = [UIColor clearColor]; _textLabel.text = @"UIScrollView"; [_scrollView addSubview:_textLabel]; - + _plusButtonsView = [[LGPlusButtonsView alloc] initWithView:_scrollView numberOfButtons:3 showsPlusButton:YES @@ -47,17 +47,19 @@ - (id)initWithTitle:(NSString *)title NSLog(@"%@, %@, %i", title, description, (int)index); } plusButtonActionHandler:nil]; - + [_plusButtonsView setButtonsTitles:@[@"+", @"1", @"2", @"3"] forState:UIControlStateNormal]; [_plusButtonsView setDescriptionsTexts:@[@"", @"Button One description", @"Button Two description", @"Button Three description"]]; _plusButtonsView.position = LGPlusButtonsViewPositionBottomRight; - _plusButtonsView.showWhenScrolling = YES; _plusButtonsView.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical; _plusButtonsView.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal; _plusButtonsView.plusButtonAnimationType = LGPlusButtonAnimationTypeRotate; [_plusButtonsView setButtonsTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_plusButtonsView setButtonsAdjustsImageWhenHighlighted:NO]; - + //_plusButtonsView.alwaysVisible = YES; + //_plusButtonsView.hideButtonsOnScroll = YES; + //_plusButtonsView.scrollSensitivity = 0.f; + [_plusButtonsView showAnimated:NO completionHandler:nil]; } return self; @@ -75,30 +77,30 @@ - (void)dealloc - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; - + _scrollView.frame = CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height); - + [_textLabel sizeToFit]; _textLabel.center = CGPointMake(_scrollView.frame.size.width/2, 20.f+_textLabel.frame.size.height/2); _textLabel.frame = CGRectIntegral(_textLabel.frame); - + _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 3000.f); - + // ----- - + BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); - + CGFloat shadowBlur = 3.f; CGFloat buttonSide = (isPortrait ? 64.f : 44.f); CGFloat buttonsFontSize = (isPortrait ? 30.f : 20.f); CGFloat plusButtonFontSize = buttonsFontSize*1.5; - + _plusButtonsView.contentInset = UIEdgeInsetsMake(shadowBlur, shadowBlur, shadowBlur, shadowBlur); [_plusButtonsView setButtonsTitleFont:[UIFont boldSystemFontOfSize:buttonsFontSize]]; - + _plusButtonsView.plusButton.titleLabel.font = [UIFont systemFontOfSize:plusButtonFontSize]; _plusButtonsView.plusButton.titleOffset = CGPointMake(0.f, -plusButtonFontSize*0.1); - + UIImage *circleImageNormal = [LGDrawer drawEllipseWithImageSize:CGSizeMake(buttonSide, buttonSide) size:CGSizeMake(buttonSide-shadowBlur*2, buttonSide-shadowBlur*2) offset:CGPointZero diff --git a/Demo/LGPlusButtonsViewDemo/PlusViewController.m b/Demo/LGPlusButtonsViewDemo/PlusViewController.m index 4fdd5ab..9af81f3 100644 --- a/Demo/LGPlusButtonsViewDemo/PlusViewController.m +++ b/Demo/LGPlusButtonsViewDemo/PlusViewController.m @@ -25,20 +25,20 @@ - (id)initWithTitle:(NSString *)title if (self) { self.title = title; - + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showHideButtonsAction)]; - + // ----- - + _contentView = [UIView new]; _contentView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_contentView]; - + _textLabel = [UILabel new]; _textLabel.backgroundColor = [UIColor clearColor]; _textLabel.text = @"UIView"; [_contentView addSubview:_textLabel]; - + _plusButtonsView = [[LGPlusButtonsView alloc] initWithView:_contentView numberOfButtons:3 showsPlusButton:NO @@ -47,11 +47,10 @@ - (id)initWithTitle:(NSString *)title NSLog(@"%@, %@, %i", title, description, (int)index); } plusButtonActionHandler:nil]; - + [_plusButtonsView setButtonsTitles:@[@"1", @"2", @"3"] forState:UIControlStateNormal]; [_plusButtonsView setDescriptionsTexts:@[@"Button One description", @"Button Two description", @"Button Three description"]]; _plusButtonsView.position = LGPlusButtonsViewPositionTopRight; - _plusButtonsView.showWhenScrolling = NO; _plusButtonsView.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop; [_plusButtonsView setButtonsTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_plusButtonsView setButtonsAdjustsImageWhenHighlighted:NO]; @@ -79,7 +78,7 @@ - (void)dealloc - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; - + CGFloat topInset = 0.f; if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0) { @@ -87,27 +86,27 @@ - (void)viewWillLayoutSubviews topInset += ([UIApplication sharedApplication].statusBarHidden ? 0.f : MIN([UIApplication sharedApplication].statusBarFrame.size.width, [UIApplication sharedApplication].statusBarFrame.size.height)); } _contentView.frame = CGRectMake(0.f, topInset, self.view.frame.size.width, self.view.frame.size.height-topInset); - + [_textLabel sizeToFit]; _textLabel.center = CGPointMake(_contentView.frame.size.width/2, _contentView.frame.size.height-20.f-_textLabel.frame.size.height/2); _textLabel.frame = CGRectIntegral(_textLabel.frame); - + // ----- - + BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation); - + CGFloat buttonSide = (isPortrait ? 64.f : 44.f); CGFloat inset = (isPortrait ? 3.f : 2.f); CGFloat buttonsFontSize = (isPortrait ? 30.f : 20.f); CGFloat plusButtonFontSize = buttonsFontSize*1.5; - + _plusButtonsView.buttonInset = UIEdgeInsetsMake(inset, inset, inset, inset); _plusButtonsView.contentInset = UIEdgeInsetsMake(inset, inset, inset, inset); [_plusButtonsView setButtonsTitleFont:[UIFont boldSystemFontOfSize:buttonsFontSize]]; - + _plusButtonsView.plusButton.titleLabel.font = [UIFont systemFontOfSize:plusButtonFontSize]; _plusButtonsView.plusButton.titleOffset = CGPointMake(0.f, -plusButtonFontSize*0.1); - + _plusButtonsView.buttonsSize = CGSizeMake(buttonSide, buttonSide); [_plusButtonsView setButtonsLayerCornerRadius:buttonSide/2]; [_plusButtonsView setButtonsLayerBorderColor:[UIColor colorWithRed:0.f green:0.f blue:0.f alpha:0.1] borderWidth:1.f]; diff --git a/Demo/LGPlusButtonsViewDemo/TableViewController.m b/Demo/LGPlusButtonsViewDemo/TableViewController.m index c4fa3da..85edbad 100644 --- a/Demo/LGPlusButtonsViewDemo/TableViewController.m +++ b/Demo/LGPlusButtonsViewDemo/TableViewController.m @@ -24,11 +24,13 @@ - (id)init if (self) { self.title = @"LGPlusButtonsView"; - + _titlesArray = @[@"UIView + Variant 1", @"UIScrollView + Variant 2"]; - + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"]; + + self.clearsSelectionOnViewWillAppear = YES; } return self; } @@ -50,10 +52,10 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger - (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; } diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 395b184..c22ae44 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,6 +1,6 @@ PODS: - LGDrawer (1.0.0) - - LGPlusButtonsView (1.0.4) + - LGPlusButtonsView (1.0.5) DEPENDENCIES: - LGDrawer (~> 1.0.0) @@ -12,6 +12,6 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: LGDrawer: 14fa657d7e21842797a6187c44d5a913841d34a8 - LGPlusButtonsView: ee15290f2e122cf43984184e3178933f3ee9e37c + LGPlusButtonsView: a99c8f6b55953faa0a15e0ce8b16690dac167d55 COCOAPODS: 0.39.0 diff --git a/LGPlusButtonsView.podspec b/LGPlusButtonsView.podspec index c0e1e72..c394ae0 100644 --- a/LGPlusButtonsView.podspec +++ b/LGPlusButtonsView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'LGPlusButtonsView' - 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/LGPlusButtonsView' diff --git a/LGPlusButtonsView/LGPlusButtonsView.h b/LGPlusButtonsView/LGPlusButtonsView.h index ae3ba08..7746fcf 100644 --- a/LGPlusButtonsView/LGPlusButtonsView.h +++ b/LGPlusButtonsView/LGPlusButtonsView.h @@ -70,8 +70,8 @@ typedef enum } LGPlusButtonAnimationType; -@property (assign, nonatomic, getter=isShowing) BOOL showing; -@property (assign, nonatomic, getter=isShowWhenScrolling) BOOL showWhenScrolling; +@property (assign, nonatomic, readonly, getter=isShowing) BOOL showing; +@property (assign, nonatomic, getter=isAlwaysVisible) BOOL alwaysVisible; @property (strong, nonatomic) LGPlusButton *plusButton; @@ -93,6 +93,12 @@ LGPlusButtonAnimationType; @property (assign, nonatomic) LGPlusButtonAnimationType plusButtonAnimationType; @property (assign, nonatomic) LGPlusButtonsViewPosition position; +/** How much scroll you need to show/hide buttons. Default is 64.f */ +@property (assign, nonatomic) CGFloat scrollSensitivity; + +/** Hide additional buttons on scroll. Default is NO */ +@property (assign, nonatomic, getter=isHideButtonsOnScroll) BOOL hideButtonsOnScroll; + /** Do not forget about weak referens to self */ @property (strong, nonatomic) void (^actionHandler)(LGPlusButtonsView *plusButtonView, NSString *title, NSString *description, NSUInteger index); /** Do not forget about weak referens to self */ diff --git a/LGPlusButtonsView/LGPlusButtonsView.m b/LGPlusButtonsView/LGPlusButtonsView.m index f0feeae..198e3c3 100644 --- a/LGPlusButtonsView/LGPlusButtonsView.m +++ b/LGPlusButtonsView/LGPlusButtonsView.m @@ -108,11 +108,11 @@ - (instancetype)initWithView:(UIView *)view if (self) { _parentView = view; - _showWhenScrolling = YES; _appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical; _buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal; _showsPlusButton = showsPlusButton; _descriptionOffsetX = 6.f; + _scrollSensitivity = 64.f; // ----- @@ -334,7 +334,7 @@ - (void)dealloc - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; - + if (!newSuperview) [self removeObservers]; else @@ -343,6 +343,14 @@ - (void)willMoveToSuperview:(UIView *)newSuperview #pragma mark - Setters and Getters +- (void)setAlwaysVisible:(BOOL)alwaysVisible +{ + _alwaysVisible = alwaysVisible; + + if (alwaysVisible) + [self showAnimated:NO completionHandler:nil]; +} + - (void)setButtonsTitles:(NSArray *)titles forState:(UIControlState)state { BOOL isChanged = NO; @@ -1035,7 +1043,7 @@ - (void)hideAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl if (result && index == _buttons.count-1) self.hidden = YES; - if (completionHandler) completionHandler(); + if (completionHandler && result) completionHandler(); }]; } } @@ -1059,7 +1067,7 @@ - (void)hideAnimated:(BOOL)animated completionHandler:(void(^)())completionHandl if (result && index == _buttons.count-1) self.hidden = YES; - if (completionHandler) completionHandler(); + if (completionHandler && result) completionHandler(); }]; } } @@ -1094,7 +1102,7 @@ - (void)showButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completi animated:animated completionHandler:^(BOOL result) { - if (completionHandler) completionHandler(); + if (completionHandler && result) completionHandler(); }]; } else @@ -1105,7 +1113,7 @@ - (void)showButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completi animated:animated completionHandler:^(BOOL result) { - if (completionHandler) completionHandler(); + if (completionHandler && result) completionHandler(); }]; } } @@ -1137,7 +1145,7 @@ - (void)hideButtonsAnimated:(BOOL)animated completionHandler:(void(^)())completi animated:animated completionHandler:^(BOOL result) { - if (completionHandler) completionHandler(); + if (completionHandler && result) completionHandler(); }]; } } @@ -1456,7 +1464,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N { [self updatePosition]; - if (self.isShowWhenScrolling) + if (!self.isAlwaysVisible) { UIScrollView *scrollView = (UIScrollView *)_parentView; @@ -1472,15 +1480,18 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N } else { - CGFloat minDiff = 64.f; CGFloat diff = self.offsetY - offsetY; - if (scrollView.isTracking && scrollView.isDragging && (diff > minDiff || diff < -minDiff)) + if (scrollView.isTracking && scrollView.isDragging && (diff > _scrollSensitivity || diff < -_scrollSensitivity)) { if (self.offsetY > offsetY) [self showAnimated:YES completionHandler:nil]; else - [self hideAnimated:YES completionHandler:nil]; + [self hideAnimated:YES completionHandler:^(void) + { + if (self.isHideButtonsOnScroll) + [self hideButtonsAnimated:NO completionHandler:nil]; + }]; } } @@ -1489,8 +1500,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N self.tempOffsetY = offsetY; } } - else - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + else [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; } #pragma mark - Support