LoginSignup
1
2

More than 3 years have passed since last update.

画面端のゴミ箱までドラッグすると、ゴミ箱が開いてコンテンツを消せるやーつです。


    // pan ジェスチャをつける
    @IBAction func pan(_ sender: UIPanGestureRecognizer) {
        panObject(recognizer: sender)
    }

    func panObject(recognizer:UIPanGestureRecognizer) {
        switch recognizer.state {

        case .changed: // 移動中
            let location = recognizer.location(in: view) // 触ってる場所を取得

            trashLabel.center = location
            if trashView.frame.contains(location) { // もしゴミ箱と重なっていたら
                // ゴミ箱を赤くする
                trashView.image = UIImage(systemName: "trash.circle.fill")
                trashView.tintColor = .red
            } else {
                // 重なっていなかったらゴミ箱を元に戻す
                trashView.image = UIImage(systemName: "trash.circle")
                trashView.tintColor = .systemBlue
            }
        default: // 指を離した時
            let location = recognizer.location(in: view) // 触ってる場所を取得
            if trashView.frame.contains(location) { // もしゴミ箱と重なっていたら
                trashLabel.removeFromSuperview() // ラベルを消す
            }
        }
    }

Apr-17-2021 01-32-01.gif

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

Twitter
Medium

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2