Skip to content

Commit b256018

Browse files
committed
Added ability to set sensitivity of show/hide when scrolling and hide additional buttons on scroll. showWhenScrolling was changed to alwaysVisible. Closes #8, closes #9
1 parent 9b70f44 commit b256018

File tree

13 files changed

+156
-71
lines changed

13 files changed

+156
-71
lines changed

Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
1946D2D8D0CE8124E0632DEA /* libPods-LGPlusButtonsViewDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 23A4E5C49FE8BEAB57D05B49 /* libPods-LGPlusButtonsViewDemo.a */; };
11+
4A1F8E611BEE098100D0B57E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */; };
1112
4A3F4B5A1AA8BA51006D9DAA /* PlusViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */; };
1213
847A899A1A9F298B004A8413 /* NavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A89971A9F298B004A8413 /* NavigationController.m */; };
1314
847A899B1A9F298B004A8413 /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847A89991A9F298B004A8413 /* TableViewController.m */; };
@@ -19,6 +20,7 @@
1920

2021
/* Begin PBXFileReference section */
2122
23A4E5C49FE8BEAB57D05B49 /* libPods-LGPlusButtonsViewDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LGPlusButtonsViewDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; };
23+
4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
2224
4A3F4B581AA8BA51006D9DAA /* PlusViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusViewController.h; sourceTree = "<group>"; };
2325
4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlusViewController.m; sourceTree = "<group>"; };
2426
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 = "<group>"; };
@@ -123,6 +125,7 @@
123125
4A3F4B5C1AA8BDAD006D9DAA /* Demo View Controllers */,
124126
84C5B7D71A9F22C800EEEB24 /* Images.xcassets */,
125127
84C5B7CA1A9F22C800EEEB24 /* Supporting Files */,
128+
4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */,
126129
);
127130
path = LGPlusButtonsViewDemo;
128131
sourceTree = "<group>";
@@ -197,6 +200,7 @@
197200
buildActionMask = 2147483647;
198201
files = (
199202
84C5B7D81A9F22C800EEEB24 /* Images.xcassets in Resources */,
203+
4A1F8E611BEE098100D0B57E /* LaunchScreen.storyboard in Resources */,
200204
);
201205
runOnlyForDeploymentPostprocessing = 0;
202206
};

Demo/LGPlusButtonsViewDemo/AppDelegate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
#import "NavigationController.h"
1110

1211
@interface AppDelegate : UIResponder <UIApplicationDelegate>
1312

1413
@property (strong, nonatomic) UIWindow *window;
15-
@property (strong, nonatomic) UINavigationController *navigationController;
1614

1715
@end

Demo/LGPlusButtonsViewDemo/AppDelegate.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
//
88

99
#import "AppDelegate.h"
10+
#import "NavigationController.h"
11+
#import "TableViewController.h"
1012

1113
@implementation AppDelegate
1214

1315
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1416
{
15-
self.navigationController = [NavigationController new];
16-
17+
TableViewController *tableViewController = [TableViewController new];
18+
NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:tableViewController];
19+
1720
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
18-
self.window.rootViewController = self.navigationController;
21+
self.window.rootViewController = navigationController;
1922
self.window.backgroundColor = [UIColor whiteColor];
2023
[self.window makeKeyAndVisible];
21-
24+
2225
return YES;
2326
}
2427

Demo/LGPlusButtonsViewDemo/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<string>1</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
25+
<key>UILaunchStoryboardName</key>
26+
<string>LaunchScreen</string>
2527
<key>UIRequiredDeviceCapabilities</key>
2628
<array>
2729
<string>armv7</string>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
6+
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<layoutGuides>
14+
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
15+
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
16+
</layoutGuides>
17+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
18+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
19+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20+
<subviews>
21+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2015 Grigory Lutkov. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
22+
<rect key="frame" x="20" y="559" width="560" height="21"/>
23+
<animations/>
24+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
25+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
26+
<nil key="highlightedColor"/>
27+
</label>
28+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LGPlusButtonsViewDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
29+
<rect key="frame" x="20" y="180" width="560" height="43"/>
30+
<animations/>
31+
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
32+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
33+
<nil key="highlightedColor"/>
34+
</label>
35+
</subviews>
36+
<animations/>
37+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
38+
<constraints>
39+
<constraint firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
40+
<constraint firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
41+
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" symbolic="YES" id="SfN-ll-jLj"/>
42+
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
43+
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
44+
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" symbolic="YES" id="x7j-FC-K8j"/>
45+
</constraints>
46+
</view>
47+
</viewController>
48+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
49+
</objects>
50+
<point key="canvasLocation" x="53" y="375"/>
51+
</scene>
52+
</scenes>
53+
</document>

Demo/LGPlusButtonsViewDemo/NavigationController.m

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,36 @@
77
//
88

99
#import "NavigationController.h"
10-
#import "TableViewController.h"
1110

1211
@interface NavigationController ()
1312

14-
@property (strong, nonatomic) TableViewController *tableViewController;
15-
1613
@end
1714

1815
@implementation NavigationController
1916

20-
- (id)init
17+
- (void)viewDidLoad
2118
{
22-
self = [super init];
23-
if (self)
24-
{
25-
self.tableViewController = [TableViewController new];
26-
[self setViewControllers:@[self.tableViewController]];
27-
}
28-
return self;
19+
[super viewDidLoad];
20+
21+
self.navigationBar.translucent = YES;
22+
self.navigationBar.barTintColor = [UIColor colorWithRed:0.f green:0.5 blue:1.f alpha:1.f];
23+
self.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
24+
self.navigationBar.tintColor = [UIColor colorWithWhite:1.f alpha:0.75];
2925
}
3026

3127
- (BOOL)shouldAutorotate
3228
{
33-
return self.topViewController.shouldAutorotate;
29+
return YES;
30+
}
31+
32+
- (BOOL)prefersStatusBarHidden
33+
{
34+
return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
35+
}
36+
37+
- (UIStatusBarStyle)preferredStatusBarStyle
38+
{
39+
return UIStatusBarStyleLightContent;
3440
}
3541

3642
@end

Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ - (id)initWithTitle:(NSString *)title
2626
if (self)
2727
{
2828
self.title = title;
29-
29+
3030
// -----
31-
31+
3232
_scrollView = [UIScrollView new];
3333
_scrollView.backgroundColor = [UIColor whiteColor];
3434
_scrollView.alwaysBounceVertical = YES;
3535
[self.view addSubview:_scrollView];
36-
36+
3737
_textLabel = [UILabel new];
3838
_textLabel.backgroundColor = [UIColor clearColor];
3939
_textLabel.text = @"UIScrollView";
4040
[_scrollView addSubview:_textLabel];
41-
41+
4242
_plusButtonsView = [[LGPlusButtonsView alloc] initWithView:_scrollView
4343
numberOfButtons:3
4444
showsPlusButton:YES
@@ -47,17 +47,19 @@ - (id)initWithTitle:(NSString *)title
4747
NSLog(@"%@, %@, %i", title, description, (int)index);
4848
}
4949
plusButtonActionHandler:nil];
50-
50+
5151
[_plusButtonsView setButtonsTitles:@[@"+", @"1", @"2", @"3"] forState:UIControlStateNormal];
5252
[_plusButtonsView setDescriptionsTexts:@[@"", @"Button One description", @"Button Two description", @"Button Three description"]];
5353
_plusButtonsView.position = LGPlusButtonsViewPositionBottomRight;
54-
_plusButtonsView.showWhenScrolling = YES;
5554
_plusButtonsView.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideVertical;
5655
_plusButtonsView.buttonsAppearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndSlideHorizontal;
5756
_plusButtonsView.plusButtonAnimationType = LGPlusButtonAnimationTypeRotate;
5857
[_plusButtonsView setButtonsTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
5958
[_plusButtonsView setButtonsAdjustsImageWhenHighlighted:NO];
60-
59+
//_plusButtonsView.alwaysVisible = YES;
60+
//_plusButtonsView.hideButtonsOnScroll = YES;
61+
//_plusButtonsView.scrollSensitivity = 0.f;
62+
6163
[_plusButtonsView showAnimated:NO completionHandler:nil];
6264
}
6365
return self;
@@ -75,30 +77,30 @@ - (void)dealloc
7577
- (void)viewWillLayoutSubviews
7678
{
7779
[super viewWillLayoutSubviews];
78-
80+
7981
_scrollView.frame = CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height);
80-
82+
8183
[_textLabel sizeToFit];
8284
_textLabel.center = CGPointMake(_scrollView.frame.size.width/2, 20.f+_textLabel.frame.size.height/2);
8385
_textLabel.frame = CGRectIntegral(_textLabel.frame);
84-
86+
8587
_scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 3000.f);
86-
88+
8789
// -----
88-
90+
8991
BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);
90-
92+
9193
CGFloat shadowBlur = 3.f;
9294
CGFloat buttonSide = (isPortrait ? 64.f : 44.f);
9395
CGFloat buttonsFontSize = (isPortrait ? 30.f : 20.f);
9496
CGFloat plusButtonFontSize = buttonsFontSize*1.5;
95-
97+
9698
_plusButtonsView.contentInset = UIEdgeInsetsMake(shadowBlur, shadowBlur, shadowBlur, shadowBlur);
9799
[_plusButtonsView setButtonsTitleFont:[UIFont boldSystemFontOfSize:buttonsFontSize]];
98-
100+
99101
_plusButtonsView.plusButton.titleLabel.font = [UIFont systemFontOfSize:plusButtonFontSize];
100102
_plusButtonsView.plusButton.titleOffset = CGPointMake(0.f, -plusButtonFontSize*0.1);
101-
103+
102104
UIImage *circleImageNormal = [LGDrawer drawEllipseWithImageSize:CGSizeMake(buttonSide, buttonSide)
103105
size:CGSizeMake(buttonSide-shadowBlur*2, buttonSide-shadowBlur*2)
104106
offset:CGPointZero

Demo/LGPlusButtonsViewDemo/PlusViewController.m

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ - (id)initWithTitle:(NSString *)title
2525
if (self)
2626
{
2727
self.title = title;
28-
28+
2929
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showHideButtonsAction)];
30-
30+
3131
// -----
32-
32+
3333
_contentView = [UIView new];
3434
_contentView.backgroundColor = [UIColor whiteColor];
3535
[self.view addSubview:_contentView];
36-
36+
3737
_textLabel = [UILabel new];
3838
_textLabel.backgroundColor = [UIColor clearColor];
3939
_textLabel.text = @"UIView";
4040
[_contentView addSubview:_textLabel];
41-
41+
4242
_plusButtonsView = [[LGPlusButtonsView alloc] initWithView:_contentView
4343
numberOfButtons:3
4444
showsPlusButton:NO
@@ -47,11 +47,10 @@ - (id)initWithTitle:(NSString *)title
4747
NSLog(@"%@, %@, %i", title, description, (int)index);
4848
}
4949
plusButtonActionHandler:nil];
50-
50+
5151
[_plusButtonsView setButtonsTitles:@[@"1", @"2", @"3"] forState:UIControlStateNormal];
5252
[_plusButtonsView setDescriptionsTexts:@[@"Button One description", @"Button Two description", @"Button Three description"]];
5353
_plusButtonsView.position = LGPlusButtonsViewPositionTopRight;
54-
_plusButtonsView.showWhenScrolling = NO;
5554
_plusButtonsView.appearingAnimationType = LGPlusButtonsAppearingAnimationTypeCrossDissolveAndPop;
5655
[_plusButtonsView setButtonsTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
5756
[_plusButtonsView setButtonsAdjustsImageWhenHighlighted:NO];
@@ -79,35 +78,35 @@ - (void)dealloc
7978
- (void)viewWillLayoutSubviews
8079
{
8180
[super viewWillLayoutSubviews];
82-
81+
8382
CGFloat topInset = 0.f;
8483
if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0)
8584
{
8685
topInset += (self.navigationController.navigationBarHidden ? 0.f : MIN(self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height));
8786
topInset += ([UIApplication sharedApplication].statusBarHidden ? 0.f : MIN([UIApplication sharedApplication].statusBarFrame.size.width, [UIApplication sharedApplication].statusBarFrame.size.height));
8887
}
8988
_contentView.frame = CGRectMake(0.f, topInset, self.view.frame.size.width, self.view.frame.size.height-topInset);
90-
89+
9190
[_textLabel sizeToFit];
9291
_textLabel.center = CGPointMake(_contentView.frame.size.width/2, _contentView.frame.size.height-20.f-_textLabel.frame.size.height/2);
9392
_textLabel.frame = CGRectIntegral(_textLabel.frame);
94-
93+
9594
// -----
96-
95+
9796
BOOL isPortrait = UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation);
98-
97+
9998
CGFloat buttonSide = (isPortrait ? 64.f : 44.f);
10099
CGFloat inset = (isPortrait ? 3.f : 2.f);
101100
CGFloat buttonsFontSize = (isPortrait ? 30.f : 20.f);
102101
CGFloat plusButtonFontSize = buttonsFontSize*1.5;
103-
102+
104103
_plusButtonsView.buttonInset = UIEdgeInsetsMake(inset, inset, inset, inset);
105104
_plusButtonsView.contentInset = UIEdgeInsetsMake(inset, inset, inset, inset);
106105
[_plusButtonsView setButtonsTitleFont:[UIFont boldSystemFontOfSize:buttonsFontSize]];
107-
106+
108107
_plusButtonsView.plusButton.titleLabel.font = [UIFont systemFontOfSize:plusButtonFontSize];
109108
_plusButtonsView.plusButton.titleOffset = CGPointMake(0.f, -plusButtonFontSize*0.1);
110-
109+
111110
_plusButtonsView.buttonsSize = CGSizeMake(buttonSide, buttonSide);
112111
[_plusButtonsView setButtonsLayerCornerRadius:buttonSide/2];
113112
[_plusButtonsView setButtonsLayerBorderColor:[UIColor colorWithRed:0.f green:0.f blue:0.f alpha:0.1] borderWidth:1.f];

Demo/LGPlusButtonsViewDemo/TableViewController.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ - (id)init
2424
if (self)
2525
{
2626
self.title = @"LGPlusButtonsView";
27-
27+
2828
_titlesArray = @[@"UIView + Variant 1",
2929
@"UIScrollView + Variant 2"];
30-
30+
3131
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
32+
33+
self.clearsSelectionOnViewWillAppear = YES;
3234
}
3335
return self;
3436
}
@@ -50,10 +52,10 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
5052
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
5153
{
5254
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
53-
55+
5456
cell.textLabel.font = [UIFont systemFontOfSize:16.f];
5557
cell.textLabel.text = _titlesArray[indexPath.row];
56-
58+
5759
return cell;
5860
}
5961

Demo/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- LGDrawer (1.0.0)
3-
- LGPlusButtonsView (1.0.4)
3+
- LGPlusButtonsView (1.0.5)
44

55
DEPENDENCIES:
66
- LGDrawer (~> 1.0.0)
@@ -12,6 +12,6 @@ EXTERNAL SOURCES:
1212

1313
SPEC CHECKSUMS:
1414
LGDrawer: 14fa657d7e21842797a6187c44d5a913841d34a8
15-
LGPlusButtonsView: ee15290f2e122cf43984184e3178933f3ee9e37c
15+
LGPlusButtonsView: a99c8f6b55953faa0a15e0ce8b16690dac167d55
1616

1717
COCOAPODS: 0.39.0

0 commit comments

Comments
 (0)