Skip to content

Commit

Permalink
Added example to show how MEVFloatingButton works with UICollectionView.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelescrig committed Aug 17, 2016
1 parent 43eb205 commit 2f72bf6
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Example/MEVFloatingButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
424DEA8C1D64DE0A002C6D42 /* MEVExample5ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 424DEA8B1D64DE0A002C6D42 /* MEVExample5ViewController.m */; };
4CA18E05DDDEE146C625B53C /* Pods_MEVFloatingButton_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C1B9420CD00A013A8C2F0D2 /* Pods_MEVFloatingButton_Tests.framework */; };
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -47,6 +48,8 @@
0C080CB97D034F7B7553480C /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
3A49046DD193E8A2C8D1A1FE /* MEVFloatingButton.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = MEVFloatingButton.podspec; path = ../MEVFloatingButton.podspec; sourceTree = "<group>"; };
419949C4815252592392460E /* Pods_MEVFloatingButton_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MEVFloatingButton_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
424DEA8A1D64DE0A002C6D42 /* MEVExample5ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MEVExample5ViewController.h; sourceTree = "<group>"; };
424DEA8B1D64DE0A002C6D42 /* MEVExample5ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MEVExample5ViewController.m; sourceTree = "<group>"; };
6003F58A195388D20070C39A /* MEVFloatingButton_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MEVFloatingButton_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
6003F58F195388D20070C39A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -156,6 +159,8 @@
C41BEAFE1C7CA7B90044AA35 /* MEVExample3ViewController.m */,
C41BEAFF1C7CA7B90044AA35 /* MEVExample4ViewController.h */,
C41BEB001C7CA7B90044AA35 /* MEVExample4ViewController.m */,
424DEA8A1D64DE0A002C6D42 /* MEVExample5ViewController.h */,
424DEA8B1D64DE0A002C6D42 /* MEVExample5ViewController.m */,
6003F5A8195388D20070C39A /* Images.xcassets */,
6003F594195388D20070C39A /* Supporting Files */,
);
Expand Down Expand Up @@ -416,6 +421,7 @@
6003F5A7195388D20070C39A /* MEVViewController.m in Sources */,
C41BEB051C7CA7B90044AA35 /* MEVExample3ViewController.m in Sources */,
6003F59A195388D20070C39A /* main.m in Sources */,
424DEA8C1D64DE0A002C6D42 /* MEVExample5ViewController.m in Sources */,
C41BEB011C7CA7B90044AA35 /* MEVExample1ViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
13 changes: 13 additions & 0 deletions Example/MEVFloatingButton/MEVExample5ViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// MEVExample5ViewController.h
// MEVFloatingButton
//
// Created by Manuel Escrig Ventura on 18/02/16.
// Copyright © 2016 Manuel Escrig Ventura. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MEVExample5ViewController : UIViewController

@end
118 changes: 118 additions & 0 deletions Example/MEVFloatingButton/MEVExample5ViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// MEVExample5ViewController.m
// MEVFloatingButton
//
// Created by Manuel Escrig Ventura on 18/02/16.
// Copyright © 2016 Manuel Escrig Ventura. All rights reserved.
//

#import "MEVExample5ViewController.h"
#import "UIScrollView+FloatingButton.h"


static NSString *CellIdentifier = @"CellIdentifier";

@interface MEVExample5ViewController () <UICollectionViewDelegate, UICollectionViewDataSource, MEVFloatingButtonDelegate>

@property (strong) UICollectionView *collectionView;

@end

@implementation MEVExample5ViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.title = @"Example 5";

UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake(100, 100);
flowLayout.minimumLineSpacing = 10;
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
[self.collectionView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
[self.view addSubview:self.collectionView];

MEVFloatingButton *button = [[MEVFloatingButton alloc] init];
button.animationType = MEFloatingButtonAnimationFadeIn;
button.displayMode = MEVFloatingButtonDisplayModeAlways;
button.position = MEVFloatingButtonPositionBottomRight;
button.image = [UIImage imageNamed:@"Icon3"];
button.imageColor = [UIColor colorWithRed:43/255.0f green:204/255.0f blue:113/255.0f alpha:1];
button.backgroundColor = [UIColor colorWithRed:154/255.0f green:18/255.0f blue:197/255.0f alpha:1];
button.outlineWidth = 0.0f;
button.imagePadding = 15.0f;
button.horizontalOffset = -30.0f;
button.verticalOffset = -30.0f;
button.rounded = YES;
button.shadowColor = [UIColor lightGrayColor];
button.shadowOffset = CGSizeMake(3, 3);
button.shadowOpacity = 0.6f;
button.shadowRadius = 3.0f;
[self.collectionView setFloatingButtonView:button];
[self.collectionView setFloatingButtonDelegate:self];

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
self.navigationItem.leftBarButtonItem = barButton;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];

[self.collectionView setFrame:self.view.frame];
}


#pragma mark - Table view data source

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 100;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setBackgroundColor:[UIColor lightGrayColor]];
return cell;
}


#pragma mark - MEScrollToTopDelegate Methods

- (void)floatingButton:(UIScrollView *)scrollView didTapButton:(UIButton *)button {
NSLog(@"didTapButton");
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)floatingButtonWillAppear:(UIScrollView *)scrollView {
NSLog(@"floatingButtonWillAppear");
}

- (void)floatingButtonDidAppear:(UIScrollView *)scrollView {
NSLog(@"floatingButtonDidAppear");
}

- (void)floatingButtonWillDisappear:(UIScrollView *)scrollView {
NSLog(@"floatingButtonWillDisappear");
}

- (void)floatingButtonDidDisappear:(UIScrollView *)scrollView; {
NSLog(@"floatingButtonDidDisappear");
}

#pragma mark - UIBarButtonItem Methods

- (void)done:(id)snder {
[self dismissViewControllerAnimated:YES completion:nil];
}


@end
8 changes: 7 additions & 1 deletion Example/MEVFloatingButton/MEVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "MEVExample2ViewController.h"
#import "MEVExample3ViewController.h"
#import "MEVExample4ViewController.h"
#import "MEVExample5ViewController.h"

static NSString *CellIdentifier = @"CellIdentifier";

Expand Down Expand Up @@ -47,7 +48,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Expand Down Expand Up @@ -84,6 +85,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
MEVExample4ViewController *viewController = [MEVExample4ViewController new];
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:viewController] animated:YES completion:nil];
} break;

case 4: {
MEVExample5ViewController *viewController = [MEVExample5ViewController new];
[self presentViewController:[[UINavigationController alloc] initWithRootViewController:viewController] animated:YES completion:nil];
} break;
default:
break;
}
Expand Down
11 changes: 10 additions & 1 deletion Pod/Classes/UIScrollView+FloatingButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @interface MEVFloatingButton ()
@property (nonatomic, strong) NSTimer *fadeOutTimer;
@property (nonatomic, assign) MEFloatingButtonState buttonState;
@property (nonatomic, assign) float scrollThreshold;
@property (nonatomic, assign) BOOL valid;

@end

Expand Down Expand Up @@ -71,6 +72,7 @@ - (instancetype)init
_verticalOffset = kMEFlatingButtonDefaultVerticalOffset;
_rounded = NO;
_hideWhenScrollToTop = NO;
_valid = NO;

[self addSubview:self.contentView];
}
Expand Down Expand Up @@ -450,9 +452,16 @@ - (void)mev_validateView
}

[view setupConstraints];

[self.floatingButton setValid:YES];
}
}

- (BOOL)mev_isViewValid
{
return [self.floatingButton valid];
}

-(void)mev_showFloatingButtonView
{
if (self.floatingButton.buttonState == MEFloatingButtonStateDidDisappear) {
Expand Down Expand Up @@ -581,7 +590,7 @@ - (void)mev_animateOutView

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:kObserverFrame]) {
if ([keyPath isEqualToString:kObserverFrame] || [self mev_isViewValid] == NO) {
[self mev_validateView];

} else if ([keyPath isEqualToString:kObserverContentOffset]) {
Expand Down

0 comments on commit 2f72bf6

Please sign in to comment.