GithubHelp home page GithubHelp logo

yammer / ymswipetableviewcell Goto Github PK

View Code? Open in Web Editor NEW
110.0 12.0 20.0 18.43 MB

YMSwipeTableViewCell is a lightweight library that enables table view cell swiping.

License: MIT License

Ruby 2.79% Objective-C 97.21%

ymswipetableviewcell's Introduction

YMSwipeTableViewCell

YMSwipeTableViewCell is a lightweight library that enables table view cell swiping (seen in most mail applications). It is implemented as a UITableViewCell class category and can detect left or right horizontal swipes. Upon a left or right swipe, a swipe view is exposed. This library is meant to be flexible, so that any views can be exposed during a swipe and a myriad of actions can be taken during the swipe (e.g., swipe view animations, or cell snap back or destruction at the completion of a swipe).

The example app shows the right view as two buttons and the left view as a single button with a checkmark's alpha increasing in proportion to the swipe content offset:

##Features

  • Users have complete control over the views exposed during a left or right swipe.

  • Configurable cell swipe effect:

    • Unmasking

- Trailing

* Block callback for cell swiping or cell mode change so that actions can be taken at any time during the swipe. * Configurable values for the snap-to-right or snap-to-left views threshold. * The ability to configure multiple cell swipe. * Low overhead and memory profile for the following reasons: - Swipe views are not added to the view until a swipe actually begins. - A cell snapshot, and not the actual cell content view, is used during the swipe animation.

##Usage

  • Implement a new cell class using the UITableViewCell class category. In this new cell class, make sure to import the class category:
#import "UITableViewCell+Swipe.h"
  • Create the desired swipe views. In this demo app, a two-button view (YMTwoButtonSwipeView) is created for the right swipe view and a single-button view (YMOneButtonSwipeView) is created for the left swipe view.

  • Initialize the left and right views:

YMTwoButtonSwipeView *rightView = [[YMTwoButtonSwipeView alloc] initWithFrame:CGRectMake(0, 0, kRightSwipeViewWidth, YMTableViewCellHeight)];
YMOneButtonSwipeView *leftView = [[YMOneButtonSwipeView alloc] init];

self.rightSwipeView = rightView;
self.leftSwipeView = leftView;
  • Set the left or right views by calling addLeftView or addRightView. If no left view is added, then the left to right swipe is disabled. If no right view is added, then the right to left swipe is disabled.
[self addLeftView:self.leftSwipeView];
[self addRightView:self.rightSwipeView];
  • Set the swipe effect (the default value is YATableSwipeEffectUnmask):
[cell setSwipeEffect:YATableSwipeEffectUnmask];
  • Set the allowMultiple flag to enable multiple cells to be swiped at once if desired (default is NO):
self.allowMultiple = YES;
  • Set the swipeContainerViewBackgroundColor to change the default swipe container view background color (default color is grayColor).
self.swipeContainerViewBackgroundColor = [UIColor grayColor];
  • Set the right and left swipe snap threshold values (the default value is 0, so right or left snaps will always occur when a swipe is initiated):
self.rightSwipeSnapThreshold = self.bounds.size.width * 0.3;
self.leftSwipeSnapThreshold = self.bounds.size.width * 0.1;
  • Set the swipeBlock to notify the subviews and/or the view controller that a swipe is occurring:
[self setSwipeBlock:^(UITableViewCell *cell, CGPoint translation){
    if (translation.x < 0) {
        [rightView didSwipeWithTranslation:translation];
    }
    else {
        [leftView didSwipeWithTranslation:translation];
    }
}];
  • Set the modeChangedBlock to notify the subviews and/or view controller that a swipe mode has changed:
[self setModeChangedBlock:^(UITableViewCell *cell, YATableSwipeMode mode){
    [leftView didChangeMode:mode];
    [rightView didChangeMode:mode];
    
    if (weakSelf.delegate) {
        [weakSelf.delegate swipeableTableViewCell:weakSelf didCompleteSwipe:mode];
    }
}];
  • Optionally set the modeWillChangeBlock to notify the subviews and/or view controller that a swipe mode will change.

  • In your view controller's cellForRowAtIndexPath delegate, instantiate the table view cell.

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YMTableViewCell *cell = (YMTableViewCell*)[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMTableViewCell class]) forIndexPath:indexPath];
    cell.delegate = self;
    if (indexPath.row % 2 == 0) {
        [cell setSwipeEffect:YATableSwipeEffectDefault];
        cell.textLabel.text = kYMSwipeTableViewCell0Title;
        cell.detailTextLabel.text = kYMSwipeTableViewCellDetailTitleSwipeLeftRight;
        cell.backgroundColor = [self unmaskingCellColor];
    } else {
        [cell setSwipeEffect:YATableSwipeEffectTrail];
        cell.textLabel.text = kYMSwipeTableViewCell1Title;
        cell.detailTextLabel.text = kYMSwipeTableViewCellDetailTitleSwipeLeftRight;
        cell.backgroundColor = [self trailingCellColor];
    }

    return cell;
}

Installation

###Option 1 Clone repo and manually add source to project.

###Option 2 Carthage:

github "yammer/YMSwipeTableViewCell"

###Option 3 CocoaPods:

pod 'YMSwipeTableViewCell', '~> 2.1.1'

##Contributing

Use Github issues to track bugs and feature requests.

##Contact

Alda Luong

Sumit Kumar

##License

YMSwipeTableViewCell is available under the MIT license. See the LICENSE file for more info.

ymswipetableviewcell's People

Contributors

aluong-yammer avatar jabobier-microsoft avatar locorocoo avatar pwillsey avatar readmecritic avatar tombuildsstuff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ymswipetableviewcell's Issues

Not working correctly when only one side swipable

Hi again!

Really annoying issue :(

When you add only on left view for example, you can easily completely block the cell by swiping one side then coming back to your original position without releasing the touch.

Here you can see the cells that are in that blocked state, not sure what is happening.

capture d ecran 2016-02-19 a 15 56 49

Programmatically open/close a cell

Hi,
is it planned or already possible to open/close a cell without swiping on it?
It could be useful when offering an alternate way (other than swipe) to show the backing views.

TIA
๐Ÿ‘ for this useful component!

Bounce cell

Hi!

I'd like to bounce slightly the left view to show users that it's possible to swipe but I'm not sure from where to start in the lib.
Any clue?

Thanks.

AccessoryType

In case using rightSwipeView at example project. When I add "cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator" rightSwipeView's right side begin after accessoryType view. Screenshot http://prntscr.com/cczcsn . Can I fix it ? It should show as usually - from right side of cell.

Swiping another cell too early cancel first one

Hi,

first of all, thanks for your awesome component!!

Small issue here : If I swipe one cell, it's animating to the LeftON position.

If I swipe another cell before the animation is complete for the firstON, the first one does reach LeftON and goes back to initial position without any animation.

It is annoying when a user is swiping a lot of cell in a small amount of time.

Any clue ?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.