ํ…Œ์ด๋ธ” ๋ทฐ์˜ reorder ๋ฒ„ํŠผ์„ ๋ณ€๊ฒฝํ•ด์•ผ ํ•˜๋Š”๋ฐ, API๊ฐ€ ์—†์–ด ๊ณ ์ƒํ–ˆ๋˜ ๊ฒฝํ—˜์„ ๊ณต์œ ํ•œ๋‹ค.

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

UITableView์˜ tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)์—์„œ cell ๋‚ด๋ถ€์— ์žˆ๋Š” UITableViewCellReorderControl๋ฅผ ๋ณ€๊ฒฝํ•˜๋ฉด ๋œ๋‹ค.

TableView

extension SomeViewController: UITableViewDelegate {
 
    public func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        self.moveRow(at: sourceIndexPath.row, to: destinationIndexPath.row) // dataSource ๋ณ€๊ฒฝ
    }
 
    public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        guard let selectedCell = cell as? ReorderControlAppearanceReplaceable else {
            return
        }
        selectedCell.replaceReorderImage()
    }
 
}

Cell

internal protocol ReorderControlAppearanceReplaceable {
 
    func replaceReorderImage()
 
}
 
internal class SomeCell: UITableViewCell, ReorderControlAppearanceReplaceable {
 
    private let reorderControlView = UIImageView(image: UIImage(image: "์ด๋ฏธ์ง€ ์ด๋ฆ„"))
 
    internal func replaceReorderImage() {
        guard let reorderControlView = self.subviews.filter({ String(describing: type(of: $0)) == "UITableViewCellReorderControl" }).first else {
            return
        }
 
        _ = reorderControlView.subviews
            .first(where: { $0 is UIImageView })
            .map {
                $0.removeFromSuperview()
            }
 
        self.reorderControlView.frame.size = CGSize(width: Constants.reorderViewWidth, height: Constants.reorderViewWidth)
 
        reorderControlView.addSubview(self.reorderControlView)
 
        self.reorderControlView <- Layouts()
            .move(to: .right, margin: .zero, alignment: nil)
            .move(toCenter: .vertical)
    }
 
}

์ •๋ฆฌ

  • ์•ฝ๊ฐ„ hack ๊ฐ™์€ ๋Š๋‚Œ์ด ์žˆ์ง€๋งŒ, ํ˜„์žฌ๋กœ์„œ๋Š” ์ด ๋ฐฉ๋ฒ•๋ฐ–์— ์—†๋‹ค๊ณ  ํ•œ๋‹ค.

Reference