项目作者: adamshin

项目描述 :
Easy UITableView drag-and-drop cell reordering
高级语言: Swift
项目地址: git://github.com/adamshin/SwiftReorder.git
创建时间: 2016-08-13T05:27:33Z
项目社区:https://github.com/adamshin/SwiftReorder

开源协议:MIT License

下载


SwiftReorder

NOTE: Some users have encountered compatibility issues when using this library with recent versions of iOS. For apps targeting iOS 11 and up, it’s recommended to use the built-in UITableView drag and drop API instead.

SwiftReorder is a UITableView extension that lets you add long-press drag-and-drop reordering to any table view. It’s robust, lightweight, and fully customizable.

Demo

Features

  • Smooth animations
  • Automatic edge scrolling
  • Works with multiple table sections
  • Customizable shadow, scaling, and transparency effects

Installation

CocoaPods

To integrate SwiftReorder into your Xcode project using CocoaPods, specify it in your Podfile:

  1. pod 'SwiftReorder', '~> 7.2'

Carthage

To integrate SwiftReorder into your Xcode project using Carthage, specify it in your Cartfile:

  1. github "adamshin/SwiftReorder" ~> 7.2

Remember to add SwiftReorder to your Carthage build phase:

  1. $(SRCROOT)/Carthage/Build/iOS/SwiftReorder.framework

and

  1. $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SwiftReorder.framework

Manually

You can integrate SwiftReorder into your project manually by copying the contents of the Source folder into your project.

Usage

Setup

  • Add the following line to your table view setup.
    1. override func viewDidLoad() {
    2. // ...
    3. tableView.reorder.delegate = self
    4. }
  • Add this code to the beginning of your tableView(_:cellForRowAt:).
    1. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    2. if let spacer = tableView.reorder.spacerCell(for: indexPath) {
    3. return spacer
    4. }
    5. // ...
    6. }
  • Implement the tableView(_:reorderRowAt:to:) delegate method, and others as necessary.
    1. extension MyViewController: TableViewReorderDelegate {
    2. func tableView(_ tableView: UITableView, reorderRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    3. // Update data model
    4. }
    5. }
    This method is analogous to the UITableViewDataSource method tableView(_:moveRowAt:to:). However, it may be called multiple times in the course of one drag-and-drop action.

Customization

SwiftReorder exposes several properties for adjusting the style of the reordering effect. For example, you can add a scaling effect to the selected cell:

  1. tableView.reorder.cellScale = 1.05

Or adjust the shadow:

  1. tableView.reorder.shadowOpacity = 0.5
  2. tableView.reorder.shadowRadius = 20