Swift UITableView subclass that supports swiping rows ala Mailbox and long press to move rows.
- Slide to trigger an action on a UITableView cell
- Two trigger levels for each left and right swipe
- Set percentages of a full swipe to activate triggers
- Set your own images and background colors for each trigger
- Triggers use closures
- Built in animation effects for swiping, unswiping and removing rows.
- Press and Hold to move a cell
- Grow and shrink animation effects
- Move triggers a closure
- Xcode 5
- iOS 7.0 +
- ARC enabled
Download source code, then drag the folder SBGestureTableView
into your project.
The best way to learn is by example, so there is an example project with the basics, but here is a more detailed guide to what can be done with SBGestureTableView.
- Using a UITableView as you usually would in a storyboard, change the class type to SBGestureTableView
- If a prototype cell doesn't exist yet, add one. Then make the type of that cell a SBGestureTableViewCell. Don't forget to set the cell identifier like you normally would.
Currently untested.
-
To enable swiping in the SBGestureTableView's cellForRowAtIndexPath delegate method, assign SBGestureTableViewAction objects to the cell's trigger actions.
- You can set up to two actions on each side (firstLeftAction, secondLeftAction, firstRightAction, and secondRightAction)
- If you don't use actions on one of the sides, that cell will not be swipable in that direction.
- An action contains four arguments:
- "icon" - a UIImage that is the icon for the swipe's action
- "color" - the background color of the action
- "fraction" - the fraction of a full swipe that the action becomes active
- "didTriggerBlock" - the action's closure that executes when the swipe is released
- The tableView already has a few built in animations to use with your actions:
- "replaceCell" - puts the cell back to where it was before the swipe action
- "fullSwipeCell" - finishes the swipe to the edge of the screen
- "removeCell" - removes the cell from the table
-
To enable the Press and Hold move action, just set a closure for the SBGestureTableView's "didMoveCellFromIndexPathToIndexPathBlock" property. Make sure that you correctly handle moving the data object to the corresponding location to the move in the table. A simple example is shown in the Example project.
-
If you don't set the "didMoveCellFromIndexPathToIndexPathBlock" property, moving rows will not be enabled.
SBGestureTableView is based on code written by David Román and Ben Vogelzang in the development of PDGestureTableView and BVReorderTableView respectively.
SBGestureTableView is copyright 2014 by Stickbuilt Inc. and is available under the MIT license. See the LICENSE file for more information. Attribution isn't required but is much appreciated.