Skip to content

Commit

Permalink
Added ability to set sensitivity of show/hide when scrolling and hide…
Browse files Browse the repository at this point in the history
… additional buttons on scroll. showWhenScrolling was changed to alwaysVisible. Closes #8, closes #9
  • Loading branch information
Friend-LGA committed Nov 7, 2015
1 parent 9b70f44 commit b256018
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 71 deletions.
4 changes: 4 additions & 0 deletions Demo/LGPlusButtonsViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
4A3F4B581AA8BA51006D9DAA /* PlusViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlusViewController.h; sourceTree = "<group>"; };
4A3F4B591AA8BA51006D9DAA /* PlusViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlusViewController.m; sourceTree = "<group>"; };
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>"; };
Expand Down Expand Up @@ -123,6 +125,7 @@
4A3F4B5C1AA8BDAD006D9DAA /* Demo View Controllers */,
84C5B7D71A9F22C800EEEB24 /* Images.xcassets */,
84C5B7CA1A9F22C800EEEB24 /* Supporting Files */,
4A1F8E601BEE098100D0B57E /* LaunchScreen.storyboard */,
);
path = LGPlusButtonsViewDemo;
sourceTree = "<group>";
Expand Down Expand Up @@ -197,6 +200,7 @@
buildActionMask = 2147483647;
files = (
84C5B7D81A9F22C800EEEB24 /* Images.xcassets in Resources */,
4A1F8E611BEE098100D0B57E /* LaunchScreen.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 0 additions & 2 deletions Demo/LGPlusButtonsViewDemo/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
//

#import <UIKit/UIKit.h>
#import "NavigationController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;

@end
11 changes: 7 additions & 4 deletions Demo/LGPlusButtonsViewDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions Demo/LGPlusButtonsViewDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
53 changes: 53 additions & 0 deletions Demo/LGPlusButtonsViewDemo/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<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">
<rect key="frame" x="20" y="559" width="560" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<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">
<rect key="frame" x="20" y="180" width="560" height="43"/>
<animations/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
<constraint firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" symbolic="YES" id="SfN-ll-jLj"/>
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" constant="20" symbolic="YES" id="x7j-FC-K8j"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
30 changes: 18 additions & 12 deletions Demo/LGPlusButtonsViewDemo/NavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 18 additions & 16 deletions Demo/LGPlusButtonsViewDemo/PlusScrollViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down
29 changes: 14 additions & 15 deletions Demo/LGPlusButtonsViewDemo/PlusViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
Expand Down Expand Up @@ -79,35 +78,35 @@ - (void)dealloc
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];

CGFloat topInset = 0.f;
if ([UIDevice currentDevice].systemVersion.floatValue >= 7.0)
{
topInset += (self.navigationController.navigationBarHidden ? 0.f : MIN(self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height));
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];
Expand Down
10 changes: 6 additions & 4 deletions Demo/LGPlusButtonsViewDemo/TableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- LGDrawer (1.0.0)
- LGPlusButtonsView (1.0.4)
- LGPlusButtonsView (1.0.5)

DEPENDENCIES:
- LGDrawer (~> 1.0.0)
Expand All @@ -12,6 +12,6 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
LGDrawer: 14fa657d7e21842797a6187c44d5a913841d34a8
LGPlusButtonsView: ee15290f2e122cf43984184e3178933f3ee9e37c
LGPlusButtonsView: a99c8f6b55953faa0a15e0ce8b16690dac167d55

COCOAPODS: 0.39.0
Loading

0 comments on commit b256018

Please sign in to comment.