3

ユーザーがセルを左にスワイプできることを示す tableView を読み込んだときに、アニメーションを実装したアプリをいくつか見てきました。スワイプされたセルがすぐに閉じて、ユーザーがやりたいことができるようになっています。

既存のライブラリをいくつか検索しましたが、見つかりませんでした。

プログラムでセルをスワイプできますか? したがって、これをviewDidLoad(または表示)で呼び出しますか?

4

2 に答える 2

1

私は間違いなく私の前に答えを2番目にします。

よりリアルにするために、アニメーションの実装を次に示します。

if let cell = tableView.cellForRow(at: IndexPath(row: 0, section: 0))
    {
        let favouriteView = createFakeFavouriteAction(frame: cell.frame)
        tableView.insertSubview(favouriteView, belowSubview: cell)

        CATransaction.begin()
        let animation = CABasicAnimation(keyPath: "position")
        animation.duration = 0.08
        animation.repeatCount = 1
        animation.autoreverses = true
        animation.speed = 0.3
        let fromPoint: CGPoint = CGPoint(x: cell.center.x, y: cell.center.y)
        animation.fromValue = NSValue(cgPoint: fromPoint)
        let toPoint: CGPoint = CGPoint(x: cell.center.x - 75, y: cell.center.y)
        animation.toValue = NSValue(cgPoint: toPoint)
        CATransaction.setCompletionBlock {
            favouriteView.removeFromSuperview()
        }
        cell.setEditing(true, animated: true)
        cell.layer.add(animation, forKey: "position")
    }

複数の UITableViewRowAction がある場合、セルの下に複数のビューを追加し、それらもアニメーション化する必要があると想像できます。私の実装は、このセルがスワイプ可能であることをユーザーに知らせる簡単な方法です。

于 2018-06-11T17:29:01.830 に答える