Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SwipeableScrollView to fix issue related to loss of didSelectRo… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 10 additions & 43 deletions SwipeableTableViewCell.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
FA57F0CD1A7573F600899C6A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA57F0CC1A7573F600899C6A /* Images.xcassets */; };
FA57F0D01A7573F600899C6A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA57F0CE1A7573F600899C6A /* LaunchScreen.xib */; };
FA57F0E71A7574E600899C6A /* SwipeableTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FA57F0E61A7574E600899C6A /* SwipeableTableViewCell.m */; };
FBDE6E951CFD11E2001F1F84 /* SwipeableScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = FBDE6E941CFD11E2001F1F84 /* SwipeableScrollView.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
FA57F0D61A7573F600899C6A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = FA57F0B41A7573F600899C6A /* Project object */;
proxyType = 1;
remoteGlobalIDString = FA57F0BB1A7573F600899C6A;
remoteInfo = SwipeableTableViewCell;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
FA57F0BC1A7573F600899C6A /* SwipeableTableViewCell.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwipeableTableViewCell.app; sourceTree = BUILT_PRODUCTS_DIR; };
FA57F0C01A7573F600899C6A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -39,6 +30,8 @@
FA57F0CF1A7573F600899C6A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
FA57F0E51A7574E600899C6A /* SwipeableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwipeableTableViewCell.h; sourceTree = "<group>"; };
FA57F0E61A7574E600899C6A /* SwipeableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SwipeableTableViewCell.m; sourceTree = "<group>"; };
FBDE6E931CFD11E2001F1F84 /* SwipeableScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwipeableScrollView.h; sourceTree = "<group>"; };
FBDE6E941CFD11E2001F1F84 /* SwipeableScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SwipeableScrollView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -49,13 +42,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
FA57F0D21A7573F600899C6A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand Down Expand Up @@ -88,6 +74,8 @@
FA57F0BF1A7573F600899C6A /* Supporting Files */,
FA57F0E51A7574E600899C6A /* SwipeableTableViewCell.h */,
FA57F0E61A7574E600899C6A /* SwipeableTableViewCell.m */,
FBDE6E931CFD11E2001F1F84 /* SwipeableScrollView.h */,
FBDE6E941CFD11E2001F1F84 /* SwipeableScrollView.m */,
);
path = SwipeableTableViewCell;
sourceTree = "<group>";
Expand Down Expand Up @@ -127,16 +115,13 @@
FA57F0B41A7573F600899C6A /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0620;
ORGANIZATIONNAME = "47 Center, Inc.";
TargetAttributes = {
FA57F0BB1A7573F600899C6A = {
CreatedOnToolsVersion = 6.2;
};
FA57F0D41A7573F600899C6A = {
CreatedOnToolsVersion = 6.2;
TestTargetID = FA57F0BB1A7573F600899C6A;
};
};
};
buildConfigurationList = FA57F0B71A7573F600899C6A /* Build configuration list for PBXProject "SwipeableTableViewCell" */;
Expand Down Expand Up @@ -168,13 +153,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
FA57F0D31A7573F600899C6A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -185,27 +163,13 @@
FA57F0E71A7574E600899C6A /* SwipeableTableViewCell.m in Sources */,
FA57F0C81A7573F600899C6A /* SwipeableTableViewController.m in Sources */,
FA57F0C51A7573F600899C6A /* AppDelegate.m in Sources */,
FBDE6E951CFD11E2001F1F84 /* SwipeableScrollView.m in Sources */,
FA57F0C21A7573F600899C6A /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
FA57F0D11A7573F600899C6A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
FA57F0D71A7573F600899C6A /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = FA57F0BB1A7573F600899C6A /* SwipeableTableViewCell */;
targetProxy = FA57F0D61A7573F600899C6A /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
FA57F0C91A7573F600899C6A /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand Down Expand Up @@ -306,16 +270,19 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = SwipeableTableViewCell/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = SwipeableTableViewCell;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
FA57F0E11A7573F600899C6A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = SwipeableTableViewCell/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = SwipeableTableViewCell;
Expand Down
15 changes: 15 additions & 0 deletions SwipeableTableViewCell/SwipeableScrollView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SwipeableScrollView.h
// SwipeableTableViewCell
//
// Created by Reinier Melian on 5/30/16.
// Copyright © 2016 47 Center, Inc. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SwipeableScrollView : UIScrollView

@property (weak,nonatomic) UIResponder * customDelegate;

@end
36 changes: 36 additions & 0 deletions SwipeableTableViewCell/SwipeableScrollView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SwipeableScrollView.m
// SwipeableTableViewCell
//
// Created by Reinier Melian on 5/30/16.
// Copyright © 2016 47 Center, Inc. All rights reserved.
//

#import "SwipeableScrollView.h"

@implementation SwipeableScrollView


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.customDelegate touchesBegan:touches withEvent:event];
}

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.customDelegate touchesMoved:touches withEvent:event];
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self.customDelegate touchesEnded:touches withEvent:event];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/

@end
3 changes: 2 additions & 1 deletion SwipeableTableViewCell/SwipeableTableViewCell.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <UIKit/UIKit.h>
#import "SwipeableScrollView.h"

typedef NS_ENUM(NSUInteger, SwipeableTableViewCellSide) {
SwipeableTableViewCellSideLeft,
Expand All @@ -23,7 +24,7 @@ extern CGFloat const kSwipeableTableViewCellOpenVelocityThreshold;
@property (nonatomic, readonly) BOOL closed;
@property (nonatomic, readonly) CGFloat leftInset;
@property (nonatomic, readonly) CGFloat rightInset;
@property (nonatomic, weak) UIScrollView *scrollView;
@property (nonatomic, weak) SwipeableScrollView *scrollView;
@property (nonatomic, weak) UIView *scrollViewContentView;
@property (nonatomic, weak) UILabel *scrollViewLabel;

Expand Down
59 changes: 48 additions & 11 deletions SwipeableTableViewCell/SwipeableTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
CGFloat const kSwipeableTableViewCellOpenVelocityThreshold = 0.6;

@interface SwipeableTableViewCell ()
{
UISwipeGestureRecognizer * swipeGrLeft;
UISwipeGestureRecognizer * swipeGrRight;
}

@property (nonatomic) NSArray *buttonViews;

Expand Down Expand Up @@ -64,11 +68,11 @@ - (void)close {
- (UIButton *)createButtonWithWidth:(CGFloat)width onSide:(SwipeableTableViewCellSide)side {
UIView *container = self.buttonViews[side];
CGSize size = container.bounds.size;

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.autoresizingMask = UIViewAutoresizingFlexibleHeight;
button.frame = CGRectMake(size.width, 0, width, size.height);

// Resize the container to fit the new button.
CGFloat x;
switch (side) {
Expand All @@ -81,13 +85,23 @@ - (UIButton *)createButtonWithWidth:(CGFloat)width onSide:(SwipeableTableViewCel
}
container.frame = CGRectMake(x, 0, size.width + width, size.height);
[container addSubview:button];

// Update the scrollable areas outside the scroll view to fit the buttons.
self.scrollView.contentInset = UIEdgeInsetsMake(0, self.leftInset, 0, self.rightInset);

return button;
}

- (void)openSideLeft
{
[self openSide:SwipeableTableViewCellSideLeft];
}

- (void)openSideRigth
{
[self openSide:SwipeableTableViewCellSideRight];
}

- (void)openSide:(SwipeableTableViewCellSide)side {
[self openSide:side animated:YES];
}
Expand Down Expand Up @@ -120,7 +134,7 @@ - (void)handleCloseEvent:(NSNotification *)notification {

- (void)setUp {
// Create the scroll view which enables the horizontal swiping.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.contentView.bounds];
SwipeableScrollView *scrollView = [[SwipeableScrollView alloc] initWithFrame:self.contentView.bounds];
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.contentSize = self.contentView.bounds.size;
scrollView.delegate = self;
Expand All @@ -129,23 +143,26 @@ - (void)setUp {
scrollView.showsVerticalScrollIndicator = NO;
[self.contentView addSubview:scrollView];
self.scrollView = scrollView;

self.scrollView.customDelegate = self;

//self.scrollView.userInteractionEnabled = NO;

// Create the containers which will contain buttons on the left and right sides.
self.buttonViews = @[[self createButtonsView], [self createButtonsView]];

// Set up main content area.
UIView *contentView = [[UIView alloc] initWithFrame:scrollView.bounds];
contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
contentView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:contentView];
self.scrollViewContentView = contentView;

// Put a label in the scroll view content area.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectInset(contentView.bounds, 10, 0)];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollViewContentView addSubview:label];
self.scrollViewLabel = label;

// Listen for events that tell cells to hide their buttons.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleCloseEvent:)
Expand All @@ -159,7 +176,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ((self.leftInset == 0 && scrollView.contentOffset.x < 0) || (self.rightInset == 0 && scrollView.contentOffset.x > 0)) {
scrollView.contentOffset = CGPointZero;
}

UIView *leftView = self.buttonViews[SwipeableTableViewCellSideLeft];
UIView *rightView = self.buttonViews[SwipeableTableViewCellSideRight];
if (scrollView.contentOffset.x < 0) {
Expand Down Expand Up @@ -193,7 +210,7 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
targetContentOffset->x = right;
} else {
*targetContentOffset = CGPointZero;

// If the scroll isn't on a fast path to zero, animate it instead.
CGFloat ms = x / -velocity.x;
if (velocity.x == 0 || ms < 0 || ms > kSwipeableTableViewCellMaxCloseMilliseconds) {
Expand All @@ -213,4 +230,24 @@ - (void)layoutSubviews {
self.scrollView.contentOffset = CGPointZero;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
if(highlighted)
[self.backgroundView setBackgroundColor:[UIColor redColor]];
else
[self.backgroundView setBackgroundColor:[UIColor whiteColor]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[[self class] closeAllCellsExcept:nil];
[super touchesBegan:touches withEvent:event];
}


@end
5 changes: 5 additions & 0 deletions SwipeableTableViewCell/SwipeableTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce
}
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%i",indexPath.row);
}

@end